package org.linlinjava.litemall.admin.service.order_manage;

import cn.com.ejiakanghu.core.exceptions.BizException;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.poi.excel.ExcelUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.linlinjava.litemall.admin.constant.CodeContent;
import org.linlinjava.litemall.admin.constant.PhoneCode;
import org.linlinjava.litemall.admin.enums.AdminErrorCode;
import org.linlinjava.litemall.admin.util.BcryptUtil;
import org.linlinjava.litemall.admin.util.TencentSendUtil;
import org.linlinjava.litemall.admin.vo.hospital_channel.HospitalChannelLinkListVo;
import org.linlinjava.litemall.admin.vo.hospital_channel.ModifyHospitalChannelLinkVo;
import org.linlinjava.litemall.admin.vo.hospital_send.*;
import org.linlinjava.litemall.admin.vo.order_manage.CommodityDetailRegualrForm;
import org.linlinjava.litemall.admin.vo.order_manage.CommodityDetailVo;
import org.linlinjava.litemall.admin.vo.shop.*;
import org.linlinjava.litemall.core.util.ExportUtils;
import org.linlinjava.litemall.core.util.InventoryUtil;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.dao.*;
import org.linlinjava.litemall.db.dao.order_manage.AgedmallShopMapper;
import org.linlinjava.litemall.db.domain.*;
import org.linlinjava.litemall.db.jsonfield.LitemallGoodsProductSpecification;
import org.linlinjava.litemall.db.vo.order_manage.AgedmallUserAgentAdminDto;
import org.linlinjava.litemall.db.vo.order_manage.BackendStoreListVo;
import org.linlinjava.litemall.db.vo.order_manage.PromoterStaticDetailIVo;
import org.linlinjava.litemall.db.vo.order_manage.PromoterstatisticalInfo;
import org.linlinjava.litemall.db.vo.shop.*;
import org.linlinjava.litemall.db.vo.store.GoodsListVo;
import org.springframework.beans.BeanUtils;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * @author wj
 * @date 2021/8/6 9:24
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class AgedmallShopService {

    @Resource
    private AgedmallBusiAdminMapper agedmallBusiAdminMapper;

    @Resource
    private LitemallAdminMapper litemallAdminMapper;

    @Resource
    private AgedmallShopMapper agedmallShopMapper;

    @Resource
    private AgedmallBusinessInfoMapper agedmallBusinessInfoMapper;

    @Resource
    private StringRedisTemplate stringRedisTemplate;


    @Resource
    private AgedmallClassifyMapper agedmallClassifyMapper;

    @Resource
    private AgedmallUserInfoMapper agedmallUserInfoMapper;

    @Resource
    private LitemallUserMapper litemallUserMapper;

    @Resource
    private AgedmallAgentMapper agedmallAgentMapper;

    @Resource
    private AgedmallAgentFinanceDetailMapper agedmallAgentFinanceDetailMapper;

    @Resource
    private LitemallGoodsMapper litemallGoodsMapper;

    @Resource
    private AgedmallCustomTemplateMapper agedmallCustomTemplateMapper;

    @Resource
    private AgedmallFreightTemplateMapper agedmallFreightTemplateMapper;

    @Resource
    private AgedmallStoreMapper agedmallStoreMapper;

    @Resource
    private AgedmallChargeTemplateMapper agedmallChargeTemplateMapper;

    @Resource
    private AgedmallMaintainTemplateMapper agedmallMaintainTemplateMapper;

    @Resource
    private AgedmallCloudHouseMapper agedmallCloudHouseMapper;

    @Resource
    private AgedmallCloudGoodsProductMapper agedmallCloudGoodsProductMapper;

    @Resource
    private LitemallGoodsProductMapper litemallGoodsProductMapper;

    @Resource
    private AgedmallCommodityService agedmallCommodityService;

    @Resource
    private AgedmallTagsMapper agedmallTagsMapper;

    @Resource
    private AgedmallCustomGoodsMapper agedmallCustomGoodsMapper;

    @Resource
    private AgedmallAnnouncerBaseInfoMapper agedmallAnnouncerBaseInfoMapper;

    @Resource
    private AgedmallVersionMapper agedmallVersionMapper;

    @Resource
    private AgedmallBusiFinancialMapper agedmallBusiFinancialMapper;

    @Resource
    private AgedmallOnlineServiceMapper agedmallOnlineServiceMapper;

    @Resource
    private AgedmallStorePositionMapper agedmallStorePositionMapper;

    @Resource
    private AgedmallStoreGoodsMapper agedmallStoreGoodsMapper;

    @Resource
    private InventoryUtil inventoryUtil;

    @Resource
    private AgedmallHospitalSendMapper agedmallHospitalSendMapper;

    @Resource
    private AgedmallHospitalSendGoodsAttributeMapper agedmallHospitalSendGoodsAttributeMapper;

    @Resource
    private AgedmallHospitalSendRelationMapper agedmallHospitalSendRelationMapper;

    @Resource
    private AgedmallHospitalChannelLinkMapper agedmallHospitalChannelLinkMapper;

    @Resource
    private AgedmallHospitalSendStoreAttributeMapper agedmallHospitalSendStoreAttributeMapper;

    @Resource
    private AgedmallCollectionPointsMapper agedmallCollectionPointsMapper;

    @Resource
    private AgedmallPromoteWithdrawalRecordMapper agedmallPromoteWithdrawalRecordMapper;

    @Resource
    private AgedmallUserAgentAdminMapper agedmallUserAgentAdminMapper;

    @Resource
    private LitemallRegionMapper litemallRegionMapper;

    @Resource
    private AgedmallHospitalSendSelfLocationMapper agedmallHospitalSendSelfLocationMapper;

    @Resource
    private AgedmallGoodsEquMapper agedmallGoodsEquMapper;

    @Resource
    private AgedmallHospitalSendSelfLocationEquMapper agedmallHospitalSendSelfLocationEquMapper;

    @Resource
    private AgedmallChargeTemplateLeasePeriodMapper agedmallChargeTemplateLeasePeriodMapper;

    public Object createShop(CreateShopVo createShopVo, Integer id) {
        String password = "123456";
        //保存店铺信息
        String bindingPhone = PhoneCode.BINDING_PHONE_ADD_SHOP;
        String redisCode = stringRedisTemplate.opsForValue().get(bindingPhone + createShopVo.getPhone());
        if (StringUtils.isNotBlank(redisCode) && redisCode.equals(createShopVo.getVerCode())) {
            AgedmallBusinessInfo agedmallBusinessInfo;
            if (createShopVo.getId() != null) {
                agedmallBusinessInfo = agedmallBusinessInfoMapper.selectByPrimaryKey(createShopVo.getId());
            } else {

                agedmallBusinessInfo = new AgedmallBusinessInfo();
            }
            agedmallBusinessInfo.setBusiName(createShopVo.getShopName());
            agedmallBusinessInfo.setPhone(createShopVo.getPhone());
            agedmallBusinessInfo.setConcat(createShopVo.getAdmin());
            agedmallBusinessInfo.setType(Integer.parseInt(createShopVo.getEshop()));
            agedmallBusinessInfo.setProvinceId(Integer.parseInt(createShopVo.getShopAddress().getShengId()));
            agedmallBusinessInfo.setProvince(createShopVo.getShopAddress().getSheng());
            agedmallBusinessInfo.setCityId(Integer.parseInt(createShopVo.getShopAddress().getShiId()));
            agedmallBusinessInfo.setCity(createShopVo.getShopAddress().getShi());
            agedmallBusinessInfo.setVillageId(Integer.parseInt(createShopVo.getShopAddress().getQuId()));
            agedmallBusinessInfo.setVillage(createShopVo.getShopAddress().getQu());
            agedmallBusinessInfo.setAddress(createShopVo.getShopAddress().getAddressDetail());
            agedmallBusinessInfo.setStat(1);
            agedmallBusinessInfo.setAddTime(LocalDateTime.now());
            if ("0".equals(createShopVo.getEshop())) {
                agedmallBusinessInfo.setBusinessLicense(createShopVo.getYyzz());
                agedmallBusinessInfo.setFilingLicense(createShopVo.getYlqxba());
                agedmallBusinessInfo.setLegalPersonPositiveCard(createShopVo.getFrSFImage().getFont());
                agedmallBusinessInfo.setLegalPersonBackCard(createShopVo.getFrSFImage().getBack());
                agedmallBusinessInfo.setLegalPersonCardNumber(createShopVo.getSfid());
                agedmallBusinessInfo.setTaxpayerNumber(createShopVo.getSid());
                agedmallBusinessInfo.setCompanyName(createShopVo.getGname());
            } else {
                agedmallBusinessInfo.setPersonCard(createShopVo.getSfid());
                agedmallBusinessInfo.setPersonPositiveCard(createShopVo.getSfImage().getFont());
                agedmallBusinessInfo.setPersonBackCard(createShopVo.getSfImage().getBack());
            }
            //插入店铺表
            if (createShopVo.getId() != null) {
                agedmallBusinessInfoMapper.updateByPrimaryKeySelective(agedmallBusinessInfo);
            } else {
                agedmallBusinessInfoMapper.insertSelective(agedmallBusinessInfo);
                //增加新用户
                LitemallAdmin admin;
                LitemallAdminExample adminExample = new LitemallAdminExample();
                adminExample.or().andUsernameEqualTo(createShopVo.getPhone());
                List<LitemallAdmin> adminList = litemallAdminMapper.selectByExample(adminExample);
                if (adminList.size() > 0) {
                    admin = adminList.get(0);
                } else {
                    admin = new LitemallAdmin();
                    admin.setUsername(createShopVo.getPhone());
                    admin.setPhone(createShopVo.getPhone());
                    admin.setAddTime(LocalDateTime.now());
                    admin.setPassword(BcryptUtil.encode(password));
                    litemallAdminMapper.insertSelective(admin);
                }
                //增加用户和店铺关联表
                AgedmallBusiAdmin agedmallBusiAdmin = new AgedmallBusiAdmin();
                agedmallBusiAdmin.setBusiId(agedmallBusinessInfo.getId());
                agedmallBusiAdmin.setUserId(admin.getId());
                agedmallBusiAdmin.setAddTime(LocalDateTime.now());
                agedmallBusiAdminMapper.insertSelective(agedmallBusiAdmin);
                //增加当前添加店铺的人和店铺的关联
                if (!id.equals(admin.getId())) {
                    AgedmallBusiAdmin agedmallBusiAdminTwo = new AgedmallBusiAdmin();
                    agedmallBusiAdminTwo.setBusiId(agedmallBusinessInfo.getId());
                    agedmallBusiAdminTwo.setUserId(id);
                    agedmallBusiAdminTwo.setAddTime(LocalDateTime.now());
                    agedmallBusiAdminMapper.insertSelective(agedmallBusiAdminTwo);
                }
                //发送消息
                String[] params = new String[1];
                params[0] = password;
                TencentSendUtil.sendSms(createShopVo.getPhone(), CodeContent.ADD_SHOP_ADMIN_MESSAGE_TEMPLATEID, params);
            }
            return ResponseUtil.ok();
        } else if (StringUtils.isNotBlank(redisCode) && !redisCode.equals(createShopVo.getVerCode())) {
            return ResponseUtil.fail(AdminErrorCode.PHONE_CODE_NOT_MATCH.getCode(), AdminErrorCode.PHONE_CODE_NOT_MATCH.getMessage());
        } else {
            return ResponseUtil.fail(AdminErrorCode.PLEASE_SEND_PHONE_CODE.getCode(), AdminErrorCode.PLEASE_SEND_PHONE_CODE.getMessage());
        }
    }


    public Object listShop(String id) {
        List<AgedmallBusinessInfo> shopListByUserId = agedmallShopMapper.getShopListByUserId(id);
        return ResponseUtil.ok(shopListByUserId);
    }

    public Object delShop(DelShop delShop) {
        String bindingPhone = PhoneCode.BINDING_PHONE_DEL_SHOP;
        String redisCode = stringRedisTemplate.opsForValue().get(bindingPhone + delShop.getContract());
        if (StringUtils.isNotBlank(redisCode) && delShop.getCode().equals(redisCode)) {
            agedmallBusinessInfoMapper.logicalDeleteByPrimaryKey(Integer.parseInt(delShop.getId()));
        } else if (StringUtils.isNotBlank(redisCode) && !delShop.getCode().equals(redisCode)) {
            return ResponseUtil.fail(AdminErrorCode.PHONE_CODE_NOT_MATCH.getCode(), AdminErrorCode.PHONE_CODE_NOT_MATCH.getMessage());
        } else {
            return ResponseUtil.fail(AdminErrorCode.PLEASE_SEND_PHONE_CODE.getCode(), AdminErrorCode.PLEASE_SEND_PHONE_CODE.getMessage());
        }
        return ResponseUtil.ok();
    }

    public Object revocatShop(String id, Integer type) {
        AgedmallBusinessInfo agedmallBusinessInfo = agedmallBusinessInfoMapper.selectByPrimaryKey(Integer.parseInt(id));
        agedmallBusinessInfo.setStat(type);
        agedmallBusinessInfoMapper.updateByPrimaryKeySelective(agedmallBusinessInfo);
        return ResponseUtil.ok();
    }


    public Object commodityClassification(CommodityClassificationVo commodityClassificationVo) {
        AgedmallClassifyExample agedmallClassifyExample = new AgedmallClassifyExample();
        agedmallClassifyExample.or().andNameEqualTo(commodityClassificationVo.getName()).andDeletedEqualTo(false);
        AgedmallClassify isNullClassify = agedmallClassifyMapper.selectOneByExample(agedmallClassifyExample);
        if (isNullClassify != null && isNullClassify.getId() != null) {
            return ResponseUtil.fail(612, "名称重复");
        }
        AgedmallClassify agedmallClassify = new AgedmallClassify();
        agedmallClassify.setName(commodityClassificationVo.getName());
        agedmallClassify.setPid(0);
        agedmallClassify.setShowSort(commodityClassificationVo.getChronologicalOrder());
        agedmallClassify.setAddTime(LocalDateTime.now());
        agedmallClassify.setDscId(1);
        agedmallClassifyMapper.insertSelective(agedmallClassify);
        List<AgedmallClassify> classifyChildList = new ArrayList<>();
        for (int i = 0; i < commodityClassificationVo.getChildren().size(); i++) {
            AgedmallClassify childClassify = new AgedmallClassify();
            childClassify.setName(commodityClassificationVo.getChildren().get(i));
            childClassify.setPid(agedmallClassify.getId());
            childClassify.setShowSort(commodityClassificationVo.getChronologicalOrder());
            childClassify.setAddTime(LocalDateTime.now());
            childClassify.setDscId(1);
            classifyChildList.add(childClassify);
        }
        agedmallShopMapper.insertClassifyBatch(classifyChildList);
        return ResponseUtil.ok();
    }

    public Object commodityClassificationEdit(CommodityClassificationVo commodityClassificationVo) {

        AgedmallClassify agedmallClassify = agedmallClassifyMapper.selectByPrimaryKey(commodityClassificationVo.getId());
        AgedmallClassifyExample agedmallClassifyExample = new AgedmallClassifyExample();
        agedmallClassifyExample.or().andNameEqualTo(commodityClassificationVo.getName()).andDeletedEqualTo(false);
        AgedmallClassify isNullClassify = agedmallClassifyMapper.selectOneByExample(agedmallClassifyExample);
        if (isNullClassify != null && isNullClassify.getId() != null && !agedmallClassify.getName().equals(commodityClassificationVo.getName())) {
            return ResponseUtil.fail(612, "名称重复");
        }
        agedmallClassify.setName(commodityClassificationVo.getName());
        agedmallClassify.setShowSort(commodityClassificationVo.getChronologicalOrder());
        agedmallClassify.setUpdateTime(LocalDateTime.now());
        agedmallClassifyMapper.updateByPrimaryKeySelective(agedmallClassify);
        AgedmallClassifyExample classifyExample = new AgedmallClassifyExample();
        classifyExample.or().andPidEqualTo(commodityClassificationVo.getId());
        List<AgedmallClassify> agedmallClassifies = agedmallClassifyMapper.selectByExample(classifyExample);
        List<Integer> clasifyIds = new ArrayList<>();
        agedmallClassifies.forEach(classify -> clasifyIds.add(classify.getId()));
        LitemallGoodsExample goodsExample = new LitemallGoodsExample();
        goodsExample.or().andCategoryTypeIn(clasifyIds);
        List<LitemallGoods> litemallGoods = litemallGoodsMapper.selectByExample(goodsExample);
        if (litemallGoods != null && !litemallGoods.isEmpty()) {
            return ResponseUtil.fail(780, "不能修改已经绑定商品的分类");
        }
        agedmallClassifyMapper.logicalDeleteByExample(classifyExample);

        //新增
        List<AgedmallClassify> classifyChildList = new ArrayList<>();
        for (int i = 0; i < commodityClassificationVo.getChildren().size(); i++) {
            AgedmallClassify childClassify = new AgedmallClassify();
            childClassify.setName(commodityClassificationVo.getChildren().get(i));
            childClassify.setPid(agedmallClassify.getId());
            childClassify.setShowSort(commodityClassificationVo.getChronologicalOrder());
            childClassify.setAddTime(LocalDateTime.now());
            childClassify.setDscId(1);
            classifyChildList.add(childClassify);
        }
        agedmallShopMapper.insertClassifyBatch(classifyChildList);
        return ResponseUtil.ok();
    }


    public Object commodityClassificationgetSecond(String id) {
        JSONObject jsonObject = JSON.parseObject(id);
        Integer cid = Integer.parseInt(jsonObject.get("id").toString());
        AgedmallClassifyExample agedmallClassifyExample = new AgedmallClassifyExample();
        agedmallClassifyExample.or().andPidEqualTo(cid).andDeletedEqualTo(false);
        List<AgedmallClassify> agedmallClassifies = agedmallClassifyMapper.selectByExample(agedmallClassifyExample);
        return ResponseUtil.ok(agedmallClassifies);
    }


    public Object commodityClassificationList(ClassifyListVo classifyListVo) {
        Page page = PageHelper.startPage(classifyListVo.getPage(), classifyListVo.getLimit());
        List<ClassifyListDto> classifyList = agedmallShopMapper.getClassifyList();
        List<OnlineServiceClassifyDto> onlineServiceClassifyCount = agedmallShopMapper.getOnlineServiceClassifyCount();
        for (int i = 0; i < classifyList.size(); i++) {
            for (int j = 0; j < onlineServiceClassifyCount.size(); j++) {
                if (classifyList.get(i).getId().equals(onlineServiceClassifyCount.get(j).getId())) {
                    Integer goodsCount = classifyList.get(i).getCountGoods();
                    Integer onlineCount = onlineServiceClassifyCount.get(j).getOnlineCount() == null ? 0 : onlineServiceClassifyCount.get(j).getOnlineCount();
                    classifyList.get(i).setCountGoods(goodsCount + onlineCount);
                }
            }
        }
        //计算在线服务数量
        List<ClassifyOnlineCountDto> classifyOnlineCountDtos = agedmallShopMapper.selectClassifyOnlineCount();
        for (int i = 0; i < classifyList.size(); i++) {
            for (int j = 0; j < classifyOnlineCountDtos.size(); j++) {
                if (classifyList.get(i).getId().equals(classifyOnlineCountDtos.get(j).getId())) {
                    Integer goodsCount = classifyList.get(i).getCountGoods();
                    Integer onlineCount = classifyOnlineCountDtos.get(j).getServiceCount() == null ? 0 : classifyOnlineCountDtos.get(j).getServiceCount();
                    classifyList.get(i).setCountGoods(goodsCount + onlineCount);
                }
            }
        }
        Map<String, Object> map = new HashMap<>();
        map.put("total", page.getTotal());
        map.put("data", classifyList);
        return ResponseUtil.ok(map);
    }

    public Object commodityClassificationDel(List<Integer> ids) {
        AgedmallClassifyExample childClassifyExample = new AgedmallClassifyExample();
        childClassifyExample.or().andPidIn(ids);
        List<AgedmallClassify> agedmallClassifies = agedmallClassifyMapper.selectByExample(childClassifyExample);
        List<Integer> childIds = new ArrayList<>();
        agedmallClassifies.forEach(childClassify -> childIds.add(childClassify.getId()));
        //因为绑定的都是二级分类。。需要获取到二级的所有id去做判断
        AgedmallOnlineServiceExample onlineServiceExample = new AgedmallOnlineServiceExample();
        onlineServiceExample.or().andClassifyIdIn(childIds).andDeletedEqualTo(false);
        AgedmallOnlineService agedmallOnlineService = agedmallOnlineServiceMapper.selectOneByExample(onlineServiceExample);
        if (ObjectUtil.isNotNull(agedmallOnlineService)) {
            return ResponseUtil.fail(630, "此分类已做关联，请先解除绑定");
        }
        LitemallGoodsExample goodsExample = new LitemallGoodsExample();
        goodsExample.or().andCategoryTypeIn(childIds).andDeletedEqualTo(false);
        LitemallGoods litemallGoods = litemallGoodsMapper.selectOneByExample(goodsExample);
        if (ObjectUtil.isNotNull(litemallGoods)) {
            return ResponseUtil.fail(630, "此分类已做关联，请先解除绑定");
        }
        AgedmallClassifyExample classifyExample = new AgedmallClassifyExample();
        classifyExample.or().andIdIn(ids);
        agedmallClassifyMapper.logicalDeleteByExample(classifyExample);
        agedmallClassifyMapper.logicalDeleteByExample(childClassifyExample);
        return ResponseUtil.ok();
    }

    public Object commodityClassificationtreeList() {
        List<AgedmallClassify> childrenClassify = agedmallShopMapper.getClassifyAllListChildren();
        List<AgedmallClassify> parentClassify = agedmallShopMapper.getClassifyAllListParent();
        List<ClassifyParent> backParents = new ArrayList<>();
        for (int i = 0; i < parentClassify.size(); i++) {
            ClassifyParent classifyParent = new ClassifyParent();
            List<ClassiftChilden> childens = new ArrayList<>();
            for (int j = 0; j < childrenClassify.size(); j++) {
                if (childrenClassify.get(j).getPid().equals(parentClassify.get(i).getId())) {
                    ClassiftChilden classiftChilden = new ClassiftChilden();
                    classiftChilden.setLabel(childrenClassify.get(j).getName());
                    classiftChilden.setValue(childrenClassify.get(j).getId());
                    childens.add(classiftChilden);
                }
            }
            classifyParent.setLabel(parentClassify.get(i).getName());
            classifyParent.setValue(parentClassify.get(i).getId());
            classifyParent.setChildren(childens);
            backParents.add(classifyParent);
        }
        return ResponseUtil.ok(backParents);
    }


    /**
     * 推广统计
     *
     * @param shopId
     * @return
     */
    public Object extensionManagementInfo(String shopId) {
        JSONObject jsonObject = JSON.parseObject(shopId);
        Integer sId = Integer.parseInt(jsonObject.get("shopId").toString());
        ExtensionInfoDto extensionInfoDto = agedmallShopMapper.getPromoteListCount(sId);
        if (extensionInfoDto != null) {
            extensionInfoDto.setOrderPriceCount(extensionInfoDto.getOrderPriceCount() == null ?
                    new BigDecimal(0.00) :
                    extensionInfoDto.getOrderPriceCount().setScale(2, BigDecimal.ROUND_DOWN));
            extensionInfoDto.setCommissionCount(extensionInfoDto.getCommissionCount() == null ?
                    new BigDecimal(0.00) :
                    extensionInfoDto.getCommissionCount().setScale(2, BigDecimal.ROUND_DOWN));
            extensionInfoDto.setIsSettlementPrice(extensionInfoDto.getIsSettlementPrice() == null ?
                    new BigDecimal(0.00) :
                    extensionInfoDto.getIsSettlementPrice().setScale(2, BigDecimal.ROUND_DOWN));
            extensionInfoDto.setUnSettlementPrice(extensionInfoDto.getUnSettlementPrice() == null ?
                    new BigDecimal(0.00) :
                    extensionInfoDto.getUnSettlementPrice().setScale(2, BigDecimal.ROUND_DOWN));
        }
        return ResponseUtil.ok(extensionInfoDto);
    }


    public Object extensionManagementGetStore(ExtensionManagementGetStoreVo emgs) {
        String[] goodsIds = emgs.getIds().split(",");
        List<Integer> ids = new ArrayList<>();
        for (int i = 0; i < goodsIds.length; i++) {
            ids.add(Integer.parseInt(goodsIds[i]));
        }
        Page page = PageHelper.startPage(emgs.getPage(), emgs.getLimit());
        List<SearchStoreListDto> searchStoreListDtos = agedmallShopMapper.selectStoreGoodsListByGoods(emgs.getProvinceId(), emgs.getCityId(),
                emgs.getAreaId(), emgs.getBusiId(), ids);
        Map<String, Object> map = new HashMap<>();
        map.put("total", page.getTotal());
        map.put("data", searchStoreListDtos);
        return ResponseUtil.ok(map);
    }


    /**
     * 根据门店id查询推广员信息及相关的统计信息
     *
     * @param extensionManagementListVo
     * @return
     */
    public Object extensionManagementList(ExtensionManagementListVo extensionManagementListVo) {
        List<PromoterListBackDto> promoterListBackDtos =
                agedmallShopMapper.selectPromoterList(extensionManagementListVo.getShopId(), extensionManagementListVo.getKeySearch());
        return ResponseUtil.ok(promoterListBackDtos);
    }


    /**
     * 查询某个推广员相关详情
     *
     * @param promoterId
     * @return
     */
    public Object getPromoteInfo(Integer promoterId) {
        //查询推广员详情
        PromoteUserInfoDto promoteUserInfoDto = agedmallShopMapper.getPromoteInfo(promoterId);
        if (ObjectUtil.isNotNull(promoteUserInfoDto)) {
            //查询推广员订单详情
            PromoteOrderNumberDto promoteOrderNumberDto = agedmallShopMapper.getPromoteOrder(promoteUserInfoDto.getUserId());
            promoteUserInfoDto.setOrderCount(promoteOrderNumberDto.getPromoteNum());
            promoteUserInfoDto.setOrderPriceCount(promoteOrderNumberDto.getSales());
            promoteUserInfoDto.setCustomerCount(promoteOrderNumberDto.getPromoteCutomerNum());
            promoteUserInfoDto.setCommissionCount(promoteOrderNumberDto.getPromoteCommission());
            promoteUserInfoDto.setIsSettlementPrice(promoteOrderNumberDto.getPromoteYesCommisson());
            promoteUserInfoDto.setUnWithdrawalPrice(promoteOrderNumberDto.getPromoteNoMoney());
            promoteUserInfoDto.setWithdrawalPrice(promoteOrderNumberDto.getPromoteYesMoney());
        }
        return ResponseUtil.ok(promoteUserInfoDto);
    }

    /**
     * 统计某个推广员的推荐的客户列表
     *
     * @param promoterId
     * @param page
     * @param limit
     * @return
     */
    public Object getCustomerSaleInfo(Integer promoterId, Integer page, Integer limit) {
        Page pages = PageHelper.startPage(page, limit);
        List<PromoteCustomerSaleDto> promoteCustomerSaleDto = agedmallShopMapper.getCustomerSaleInfo(promoterId);
        Map<String, Object> map = new HashMap<>();
        map.put("total", pages.getTotal());
        map.put("data", promoteCustomerSaleDto);
        return ResponseUtil.ok(map);
    }


    /**
     * 获取推广统计
     *
     * @param promoterStaticDetailIVo
     * @return
     */
    public Object staticDetail(PromoterStaticDetailIVo promoterStaticDetailIVo) {
        Page pages = PageHelper.startPage(promoterStaticDetailIVo.getPage(), promoterStaticDetailIVo.getLimit());
        List<PromoterstatisticalInfo> promoterstatisticalInfoList = agedmallShopMapper.getPromoterStatistical(promoterStaticDetailIVo);
        Map<String, Object> map = new HashMap<>();
        map.put("total", pages.getTotal());
        map.put("data", promoterstatisticalInfoList);
        return ResponseUtil.ok(map);
    }


    public void exportList(HSSFWorkbook workbook, PromoterStaticDetailIVo promoterStaticDetailIVo) {
        //headers表示excel表中第一行的表头
        String[] headers = {"日期", "累计订单(/个)", "累计销售额", "累计客户(/个)", "累计佣金", "已结算", "待结算", "推广客户(/个)", "访问用户(/个)",};
        List<Map<Integer, String>> dataMapList = this.getCDataMapList(promoterStaticDetailIVo);
        ExportUtils.dealHSSFWorkbook(workbook, headers, "推广", dataMapList, false);

    }


    private List<Map<Integer, String>> getCDataMapList(PromoterStaticDetailIVo promoterStaticDetailIVo) {
        //查询数据库获得原始列表数据
        List<PromoterstatisticalInfo> list = agedmallShopMapper.getPromoterStatistical(promoterStaticDetailIVo);
        //在表中存放查询到的数据放入对应的列
        List<Map<Integer, String>> dataMapList = Lists.newArrayList();
        if (CollectionUtils.isNotEmpty(list)) {
            list.forEach(vo -> {
                Map<Integer, String> map = Maps.newHashMap();
                int columnNumber = 0;
                map.put(columnNumber++, vo.getPromoterDate());//日期
                map.put(columnNumber++, vo.getOrderCount() == null ? "0" : vo.getOrderCount().toString());//累计订单
                map.put(columnNumber++, vo.getOrderPriceCount() == null ? BigDecimal.ZERO.toString() : vo.getOrderPriceCount().setScale(2, BigDecimal.ROUND_HALF_UP).toString());//累计销售额
                map.put(columnNumber++, vo.getCustomerCount() == null ? "0" : vo.getCustomerCount().toString());
                map.put(columnNumber++, vo.getCommissionCount() == null ? BigDecimal.ZERO.toString() : vo.getCommissionCount().setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                map.put(columnNumber++, vo.getIsSettlementPrice() == null ? BigDecimal.ZERO.toString() : vo.getIsSettlementPrice().setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                map.put(columnNumber++, vo.getUnSettlementPrice() == null ? BigDecimal.ZERO.toString() : vo.getUnSettlementPrice().setScale(2, BigDecimal.ROUND_HALF_UP).toString());
                map.put(columnNumber++, vo.getPromoterCount() == null ? "0" : vo.getPromoterCount().toString());
                map.put(columnNumber++, vo.getVisitorCount() == null ? "0" : vo.getVisitorCount().toString());
                dataMapList.add(map);
            });
        }
        return dataMapList;
    }


    /**
     * 推广管理-获取代理列表
     *
     * @param shopId
     * @return
     */
    public Object proxyList(Integer shopId) {
        AgedmallUserAgentAdminExample userAgentAdminExample = new AgedmallUserAgentAdminExample();
        userAgentAdminExample.or().andDeleteEqualTo(false).andShopidEqualTo(shopId.toString());
        List<AgedmallUserAgentAdmin> userAgentAdminList = agedmallUserAgentAdminMapper.selectByExample(userAgentAdminExample);
        List<AgedmallUserAgentAdminDto> agedmallUserAgentAdminDtoList = new ArrayList<>();
        for (AgedmallUserAgentAdmin agent : userAgentAdminList) {


            AgedmallUserAgentAdminDto agentAdminDto = new AgedmallUserAgentAdminDto();
            agentAdminDto.setId(agent.getId());
            agentAdminDto.setName(agent.getUserAgentName());
            agentAdminDto.setType(agent.getType());
            agedmallUserAgentAdminDtoList.add(agentAdminDto);
        }
        return ResponseUtil.ok(agedmallUserAgentAdminDtoList);
    }

    /**
     * 提现记录
     *
     * @param promoterId
     * @return
     */
    public Object getWithdrawalMoney(String promoterId) {
        JSONObject jsonObject = JSON.parseObject(promoterId);
        Integer cid = Integer.parseInt(jsonObject.get("promoterId").toString());
        AgedmallPromoteWithdrawalRecordExample withdrawalRecordExample = new AgedmallPromoteWithdrawalRecordExample();
        withdrawalRecordExample.or().andUserIdEqualTo(cid);
        withdrawalRecordExample.setOrderByClause("add_time desc");
        List<AgedmallPromoteWithdrawalRecord> withdrawalRecordList = agedmallPromoteWithdrawalRecordMapper.selectByExample(withdrawalRecordExample);
        return ResponseUtil.ok(withdrawalRecordList);
    }

    /**
     * 获取推广员推荐的下单信息
     *
     * @param promoterId
     * @param page
     * @param limit
     * @return
     */
    public Object getUserOrderRecommendInfo(Integer promoterId, Integer page, Integer limit) {
        return null;
    }


   /* public Object extensionManagementPromoterDetail(String promoterId) {
        JSONObject jsonObject = JSON.parseObject(promoterId);
        Integer userId = Integer.parseInt(jsonObject.get("promoterId").toString());
        PromoterInfo promoterInfo = new PromoterInfo();
        //获取推广累计订单
        Integer orderCount = agedmallShopMapper.getExtensionOrderCount(null, userId);
        //获取推广累计销售额
        BigDecimal orderPriceCount = agedmallShopMapper.getExtensionOrderPriceCount(null, userId);
        //累计客户
        Integer customerCount = agedmallShopMapper.getExtensionCustomerCount(null, userId);
        //累计佣金
        BigDecimal commissionCount = agedmallShopMapper.getExtensionCommissionCount(null, userId);
        //已结算佣金
        BigDecimal isSettlementPrice = agedmallShopMapper.getExtensionIsSettlementPrice(null, userId);
        //未结算佣金
        BigDecimal unSettlementPrice = agedmallShopMapper.getExtensionUnSettlementPrice(null, userId);
        //未提现金额
        AgedmallUserInfoExample userInfoExample = new AgedmallUserInfoExample();
        userInfoExample.or().andUserIdEqualTo(userId);
        List<AgedmallUserInfo> agedmallUserInfos = agedmallUserInfoMapper.selectByExample(userInfoExample);
        //已提现金额
        BigDecimal withdrawalPriceByUserId = agedmallShopMapper.getWithdrawalPriceByUserId(userId);
        promoterInfo.setOrderCount(orderCount == null ? 0 : orderCount);
        promoterInfo.setOrderPriceCount(orderPriceCount == null ? new BigDecimal(0) : orderPriceCount);
        promoterInfo.setCustomerCount(customerCount == null ? 0 : customerCount);
        promoterInfo.setCommissionCount(commissionCount == null ? new BigDecimal(0) : commissionCount);
        promoterInfo.setIsSettlementPrice(isSettlementPrice == null ? new BigDecimal(0) : isSettlementPrice);
        promoterInfo.setUnSettlementPrice(unSettlementPrice == null ? new BigDecimal(0) : unSettlementPrice);
        promoterInfo.setUnWithdrawalPrice(agedmallUserInfos.get(0).getAgentAmount() == null ? new BigDecimal(0) : agedmallUserInfos.get(0).getAgentAmount());
        promoterInfo.setWithdrawalPrice(withdrawalPriceByUserId == null ? new BigDecimal(0) : withdrawalPriceByUserId);
        return ResponseUtil.ok(promoterInfo);
    }*/


    /**
     * 推广管理-推广员-详情-订单列表
     *
     * @param promoterListVo
     * @return
     */
    public Object extensionManagementPromoterList(PromoterListVo promoterListVo) {
        Page page = PageHelper.startPage(promoterListVo.getPage(), promoterListVo.getLimit());
        List<promoterOrderInfo> promoterOrderInfoList = agedmallShopMapper.getUserOrderRecommendInfo(promoterListVo.getPromoterId(), promoterListVo.getKeySearch());
        Set<Integer> promoteIdList = new HashSet<>();
        for (promoterOrderInfo pod : promoterOrderInfoList) {
            promoteIdList.add(pod.getPromoteId());
        }
        //查询推广列表
        List<PromoterCommissionOrder> promoterCommissionOrderList = null;
        if (!promoterOrderInfoList.isEmpty()) {
            promoterCommissionOrderList = agedmallShopMapper.getPromoterOrderInfo(promoteIdList, promoterListVo.getType());
        }
        List<promoterOrderInfo> promoterOrderInfos = new ArrayList<>();
        for (promoterOrderInfo poi : promoterOrderInfoList) {
            promoterOrderInfo orderInfo = new promoterOrderInfo();
            BeanUtils.copyProperties(poi, orderInfo);
            List<PromoterCommissionOrder> commissionOrderList = new ArrayList<>();
            if (!promoterCommissionOrderList.isEmpty()) {
                for (PromoterCommissionOrder pco : promoterCommissionOrderList) {
                    if (poi.getChildOrderId().equals(pco.getChildOrderId())) {
                        PromoterCommissionOrder commissionOrder = new PromoterCommissionOrder();
                        List<LitemallGoodsProductSpecification> specifications
                                = JSON.parseArray(pco.getSkuName(), LitemallGoodsProductSpecification.class);
                        StringBuffer sb = new StringBuffer();
                        if (specifications.size() > 0) {
                            for (LitemallGoodsProductSpecification lgps : specifications) {
                                sb.append(lgps.getInfoName()).append(",");
                            }
                            String InfoName = sb.substring(0, sb.length() - 1);
                            pco.setSkuName(InfoName);
                        }
                        BeanUtils.copyProperties(pco, commissionOrder);
                        commissionOrderList.add(commissionOrder);
                    }
                }
            }
            orderInfo.setGoodsList(commissionOrderList);
            promoterOrderInfos.add(orderInfo);
        }
        Map<String, Object> map = new HashMap<>();
        map.put("total", page.getTotal());
        map.put("data", promoterOrderInfos);
        return ResponseUtil.ok(map);
    }


    public Object inventoryManagementAdd(InventoryManagementAddVo inventoryManagementAddVo) {
        String password = "123456";
        LitemallUser litemallUser;
        LitemallUserExample userExample = new LitemallUserExample();
        userExample.or().andMobileEqualTo(inventoryManagementAddVo.getPhone());
        litemallUser = litemallUserMapper.selectOneByExample(userExample);
        if (ObjectUtil.isNull(litemallUser)) {
            litemallUser = new LitemallUser();
            litemallUser.setUsername(inventoryManagementAddVo.getPhone());
            litemallUser.setNickname(inventoryManagementAddVo.getName());
            litemallUser.setMobile(inventoryManagementAddVo.getPhone());
            litemallUser.setPassword(BcryptUtil.encode(password));
            litemallUser.setGender((byte) 0);
            litemallUser.setUserLevel((byte) 0);
            litemallUser.setStatus((byte) 0);
            litemallUser.setAddTime(LocalDateTime.now());
            litemallUserMapper.insertSelective(litemallUser);
        } else {
            litemallUser.setNickname(inventoryManagementAddVo.getName());
            litemallUserMapper.updateByPrimaryKeySelective(litemallUser);
        }
        AgedmallAgent agedmallAgent = new AgedmallAgent();
        agedmallAgent.setUserId(litemallUser.getId());
        agedmallAgent.setType((byte) 1);
        agedmallAgent.setShopId(inventoryManagementAddVo.getShopId());
        agedmallAgent.setPromotionScheme(inventoryManagementAddVo.getProgramme().longValue());
        agedmallAgent.setAddTime(LocalDateTime.now());
        if (inventoryManagementAddVo.getRemark() != null) {
            agedmallAgent.setNote(inventoryManagementAddVo.getRemark());
        }
        if (inventoryManagementAddVo.getProxy() != null) {
            agedmallAgent.setAgentId(inventoryManagementAddVo.getProxy());//代理id
        }
        if (inventoryManagementAddVo.getImages() != null) {
            agedmallAgent.setImages(StringUtils.join(inventoryManagementAddVo.getImages(), ","));
        }
        agedmallAgent.setProvinceCode(Integer.parseInt(inventoryManagementAddVo.getProvinceCode()));//省code
        agedmallAgent.setCityCode(Integer.parseInt(inventoryManagementAddVo.getCityCode()));//市code
        agedmallAgent.setAreaCode(Integer.parseInt(inventoryManagementAddVo.getVillageCode()));//区县code
        agedmallAgentMapper.insertSelective(agedmallAgent);
        return ResponseUtil.ok();
    }


    public Object inventoryManagementEdit(InventoryManagementEditVo inventoryManagementAddVo) {
        LitemallUser litemallUser;

        //编辑用户信息
        LitemallUserExample userExample = new LitemallUserExample();
        userExample.or().andMobileEqualTo(inventoryManagementAddVo.getPhone());
        litemallUser = litemallUserMapper.selectOneByExample(userExample);
        litemallUser.setNickname(inventoryManagementAddVo.getName());
        litemallUser.setMobile(inventoryManagementAddVo.getPhone());
        litemallUserMapper.updateByPrimaryKeySelective(litemallUser);


        AgedmallAgentExample agedmallAgentExample = new AgedmallAgentExample();
        agedmallAgentExample.or().andIdEqualTo(inventoryManagementAddVo.getAgentId());
        AgedmallAgent agedmallAgents = agedmallAgentMapper.selectOneByExample(agedmallAgentExample);

        agedmallAgents.setPromotionScheme(inventoryManagementAddVo.getProgramme().longValue());
        agedmallAgents.setUserId(litemallUser.getId());
        agedmallAgents.setShopId(inventoryManagementAddVo.getShopId());
        agedmallAgents.setProvinceCode(Integer.parseInt(inventoryManagementAddVo.getProvinceCode()));
        agedmallAgents.setCityCode(Integer.parseInt(inventoryManagementAddVo.getCityCode()));
        agedmallAgents.setAreaCode(Integer.parseInt(inventoryManagementAddVo.getVillageCode()));
        if (inventoryManagementAddVo.getProxy() != null) {
            agedmallAgents.setAgentId(inventoryManagementAddVo.getProxy());
        }
        if (inventoryManagementAddVo.getImages() != null) {
            agedmallAgents.setImages(StringUtils.join(inventoryManagementAddVo.getImages(), ","));
        }
        if (inventoryManagementAddVo.getRemark() != null) {
            agedmallAgents.setNote(inventoryManagementAddVo.getRemark());
        }
        agedmallAgentMapper.updateByPrimaryKeySelective(agedmallAgents);
        return ResponseUtil.ok();
    }

    public Object extensionManagementDelPromoter(String promoterId) {
        JSONObject jsonObject = JSON.parseObject(promoterId);
        Integer cid = Integer.parseInt(jsonObject.get("promoterId").toString());
        AgedmallAgentExample agedmallAgentExample = new AgedmallAgentExample();
        agedmallAgentExample.or().andUserIdEqualTo(cid).andDeletedEqualTo(false);
        AgedmallAgent agedmallAgent = agedmallAgentMapper.selectOneByExample(agedmallAgentExample);
        agedmallAgent.setDeleted(true);
        agedmallAgentMapper.updateByPrimaryKeySelective(agedmallAgent);
        LitemallUserExample userExample = new LitemallUserExample();
        userExample.or().andIdEqualTo(agedmallAgent.getUserId());
        LitemallUser litemallUsers = litemallUserMapper.selectOneByExample(userExample);
        litemallUsers.setDeleted(true);
        litemallUserMapper.updateByPrimaryKey(litemallUsers);
        return ResponseUtil.ok();
    }

    public Object extensionManagementLJKH(String promoterId) {
        JSONObject jsonObject = JSON.parseObject(promoterId);
        Integer cid = Integer.parseInt(jsonObject.get("promoterId").toString());
        List<PromoteCustomerSaleDto> promoteCustomerSaleDto = agedmallShopMapper.getCustomerSaleInfo(cid);
        return ResponseUtil.ok(promoteCustomerSaleDto);
    }

    public Object extensionManagementTXJL(String promoterId) {
        JSONObject jsonObject = JSON.parseObject(promoterId);
        Integer cid = Integer.parseInt(jsonObject.get("promoterId").toString());
        AgedmallAgentFinanceDetailExample financeDetailExample = new AgedmallAgentFinanceDetailExample();
        financeDetailExample.or().andUserIdEqualTo(cid).andTypeEqualTo((byte) 2);
        List<AgedmallAgentFinanceDetail> agedmallAgentFinanceDetails = agedmallAgentFinanceDetailMapper.selectByExample(financeDetailExample);
        return ResponseUtil.ok(agedmallAgentFinanceDetails);
    }

    public Object schemeList(SchemeListVo schemeListVo) {
        Page page = PageHelper.startPage(schemeListVo.getPage(), schemeListVo.getLimit());
        List<CustomTemplateListDto> customTemplateListDtos = agedmallShopMapper.selectCustomTemplateList(
                schemeListVo.getShopId(), schemeListVo.getKeySearch());
        List<CustomGoodsListDto> customGoodsListDtos = agedmallShopMapper.selectCustomGoodsList(schemeListVo.getShopId(), null, null, null, null);
        for (int i = 0; i < customTemplateListDtos.size(); i++) {
            if (customTemplateListDtos.get(i).getCanCustomGoodsType() == 0) {
                customTemplateListDtos.get(i).setGoodsCount(customGoodsListDtos.size());
            } else if (customTemplateListDtos.get(i).getCanCustomGoodsType() == 1) {
                String[] chooseGoods = customTemplateListDtos.get(i).getCanCustomGoods().split(",");
                customTemplateListDtos.get(i).setGoodsCount(chooseGoods.length);
            } else if (customTemplateListDtos.get(i).getCanCustomGoodsType() == 2) {
                String[] chooseGoods = customTemplateListDtos.get(i).getCanCustomGoods().split(",");
                ArrayList<Integer> goodsList = new ArrayList<>(chooseGoods.length);
                for (int j = 0; j < chooseGoods.length; j++) {
                    goodsList.add(Integer.parseInt(chooseGoods[j]));
                }
                String[] chooseStores = customTemplateListDtos.get(i).getCanCustomStore().split(",");
                ArrayList<Integer> storesList = new ArrayList<>(chooseStores.length);
                for (int j = 0; j < chooseStores.length; j++) {
                    storesList.add(Integer.parseInt(chooseStores[j]));
                }
                List<LitemallGoods> beChooseGoodsList = agedmallShopMapper.selectGoodsListBySearchGoods(storesList, goodsList);
                customTemplateListDtos.get(i).setGoodsCount(beChooseGoodsList.size());
            }
        }
        Map<String, Object> map = new HashMap<>();
        map.put("total", page.getTotal());
        map.put("data", customTemplateListDtos);
        return ResponseUtil.ok(map);
    }

    public Object schemeDetail(String schemeId) {
        JSONObject jsonObject = JSON.parseObject(schemeId);
        Integer cid = Integer.parseInt(jsonObject.get("schemeId").toString());
        SchemeDetailBack schemeDetailBack = new SchemeDetailBack();
        AgedmallCustomTemplate agedmallCustomTemplate = agedmallCustomTemplateMapper.selectByPrimaryKey(cid);
        BeanUtils.copyProperties(agedmallCustomTemplate, schemeDetailBack);
        List<Long> allGoodsId = new ArrayList<>();
        if (schemeDetailBack.getCanCustomGoodsType() == 0) {
            LitemallGoodsExample goodsExample = new LitemallGoodsExample();
            goodsExample.or().andBusIdEqualTo(agedmallCustomTemplate.getBusId().intValue());
            List<LitemallGoods> allGoods = litemallGoodsMapper.selectByExample(goodsExample);
            allGoods.forEach(goods -> {
                allGoodsId.add(goods.getId().longValue());
            });
            schemeDetailBack.setGoodsList(allGoods);
        } else if (schemeDetailBack.getCanCustomGoodsType() == 1) {
            String[] chooseGoods = schemeDetailBack.getCanCustomGoods().split(",");
            ArrayList<Integer> arrayList = new ArrayList<>(chooseGoods.length);
            for (int j = 0; j < chooseGoods.length; j++) {
                arrayList.add(Integer.parseInt(chooseGoods[j]));
                allGoodsId.add(Long.parseLong(chooseGoods[j]));
            }
            LitemallGoodsExample goodsExample = new LitemallGoodsExample();
            goodsExample.or().andIdIn(arrayList);
            List<LitemallGoods> chooseGoodsList = litemallGoodsMapper.selectByExample(goodsExample);
            schemeDetailBack.setGoodsList(chooseGoodsList);
        } else if (schemeDetailBack.getCanCustomGoodsType() == 2) {
            String[] chooseGoods = schemeDetailBack.getCanCustomGoods().split(",");
            List<Integer> goodsList = new ArrayList<>(chooseGoods.length);
            for (int j = 0; j < chooseGoods.length; j++) {
                goodsList.add(Integer.parseInt(chooseGoods[j]));
            }
//            String[] chooseStores = schemeDetailBack.getCanCustomStore().split(",");
//            ArrayList<Integer> storesList = new ArrayList<>(chooseStores.length);
//            for (int j = 0; j < chooseStores.length; j++) {
//                storesList.add(Integer.parseInt(chooseStores[j]));
//            }
//            List<LitemallGoods> beChooseGoodsList = agedmallShopMapper.selectGoodsListBySearchGoods(storesList, goodsList);
//            beChooseGoodsList.forEach(goods -> {
//                allGoodsId.add(goods.getId().longValue());
//            });
//            schemeDetailBack.setGoodsList(beChooseGoodsList);
            goodsList.forEach(goodsId -> allGoodsId.add(goodsId.longValue()));
            LitemallGoodsExample goodsExample = new LitemallGoodsExample();
            goodsExample.or().andIdIn(goodsList);
            List<LitemallGoods> litemallGoods = litemallGoodsMapper.selectByExampleWithBLOBs(goodsExample);
            schemeDetailBack.setGoodsList(litemallGoods);
        }

        if (schemeDetailBack.getCanCustomStoreType() == 0) {
            AgedmallStoreGoodsExample storeGoodsExample = new AgedmallStoreGoodsExample();
            storeGoodsExample.or().andDeletedEqualTo(false).andGoodsIdIn(allGoodsId);
            List<AgedmallStoreGoods> agedmallStoreGoods = agedmallStoreGoodsMapper.selectByExample(storeGoodsExample);
            List<Long> storeList = new ArrayList<>();
            agedmallStoreGoods.forEach(storeGoods -> storeList.add(storeGoods.getStoreId()));
            AgedmallStoreExample agedmallStoreExample = new AgedmallStoreExample();
            agedmallStoreExample.or().andBusiIdEqualTo(agedmallCustomTemplate.getBusId().intValue()).andIdIn(storeList);
            List<AgedmallStore> allStore = agedmallStoreMapper.selectByExample(agedmallStoreExample);
            schemeDetailBack.setStoreList(allStore);
        } else if (schemeDetailBack.getCanCustomStoreType() == 1) {
            String[] chooseStores = schemeDetailBack.getCanCustomStore().split(",");
            ArrayList<Long> arrayList = new ArrayList<>(chooseStores.length);
            for (int j = 0; j < chooseStores.length; j++) {
                arrayList.add(Long.parseLong(chooseStores[j]));
            }
            AgedmallStoreExample agedmallStoreExample = new AgedmallStoreExample();
            agedmallStoreExample.or().andIdIn(arrayList);
            List<AgedmallStore> beChooseStores = agedmallStoreMapper.selectByExample(agedmallStoreExample);
            schemeDetailBack.setStoreList(beChooseStores);
        }
        return ResponseUtil.ok(schemeDetailBack);
    }

    public Object schemeAdd(SchemeAddVo schemeAddVo) {
        AgedmallCustomTemplate agedmallCustomTemplate = new AgedmallCustomTemplate();
        AgedmallCustomTemplateExample templateExample = new AgedmallCustomTemplateExample();
        templateExample.or().andNameEqualTo(schemeAddVo.getSchemeName()).andDeletedEqualTo(false);
        AgedmallCustomTemplate isUserNameCustom = agedmallCustomTemplateMapper.selectOneByExample(templateExample);
        if (ObjectUtil.isNotNull(isUserNameCustom)) {
            return ResponseUtil.fail(612, "名称重复");
        }
        agedmallCustomTemplate.setName(schemeAddVo.getSchemeName());
        agedmallCustomTemplate.setBusId(schemeAddVo.getShopId().longValue());
        agedmallCustomTemplate.setDivideType(schemeAddVo.getProportionalShare());
        agedmallCustomTemplate.setConsumptionType(schemeAddVo.getdModeTypeId());
        agedmallCustomTemplate.setConsumptionPrice(schemeAddVo.getdMode());
        agedmallCustomTemplate.setCanCustomExtension(schemeAddVo.getCustom());
        agedmallCustomTemplate.setCanCustomGoodsType(schemeAddVo.getGoodsType());
        agedmallCustomTemplate.setCanCustomGoods(schemeAddVo.getGoodsId());
        agedmallCustomTemplate.setCanCustomStoreType(schemeAddVo.getStoreType());
        agedmallCustomTemplate.setCanCustomStore(schemeAddVo.getStoreId());
        agedmallCustomTemplate.setAusleseShow(schemeAddVo.getAusleseShow());
        agedmallCustomTemplate.setAusleseBackgroundTitle(schemeAddVo.getAusleseBackgroundTitle());
        agedmallCustomTemplate.setAusleseBackgroundContent(schemeAddVo.getAusleseBackgroundContent());
        agedmallCustomTemplate.setAusleseBackgroundImage(schemeAddVo.getAusleseBackgroundImage());
        agedmallCustomTemplate.setAddTime(LocalDateTime.now());
        agedmallCustomTemplateMapper.insertSelective(agedmallCustomTemplate);
        return ResponseUtil.ok();
    }

    public Object schemeEdit(SchemeEditVo schemeEditVo) {
        AgedmallCustomTemplate agedmallCustomTemplate = agedmallCustomTemplateMapper.selectByPrimaryKey(schemeEditVo.getSchemeId());
        AgedmallCustomTemplateExample templateExample = new AgedmallCustomTemplateExample();
        templateExample.or().andNameEqualTo(schemeEditVo.getSchemeName()).andDeletedEqualTo(false);
        AgedmallCustomTemplate isUserNameCustom = agedmallCustomTemplateMapper.selectOneByExample(templateExample);
        if (ObjectUtil.isNotNull(isUserNameCustom) && !agedmallCustomTemplate.getName().equals(schemeEditVo.getSchemeName())) {
            return ResponseUtil.fail(612, "名称重复");
        }
        agedmallCustomTemplate.setName(schemeEditVo.getSchemeName());
        agedmallCustomTemplate.setDivideType(schemeEditVo.getProportionalShare());
        agedmallCustomTemplate.setConsumptionType(schemeEditVo.getdModeTypeId());
        agedmallCustomTemplate.setConsumptionPrice(schemeEditVo.getdMode());
        agedmallCustomTemplate.setCanCustomExtension(schemeEditVo.getCustom());
        agedmallCustomTemplate.setCanCustomGoodsType(schemeEditVo.getGoodsType());
        agedmallCustomTemplate.setCanCustomGoods(schemeEditVo.getGoodsId());
        agedmallCustomTemplate.setCanCustomStoreType(schemeEditVo.getStoreType());
        agedmallCustomTemplate.setCanCustomStore(schemeEditVo.getStoreId());
        agedmallCustomTemplate.setAusleseShow(schemeEditVo.getAusleseShow());
        agedmallCustomTemplate.setAusleseBackgroundTitle(schemeEditVo.getAusleseBackgroundTitle());
        agedmallCustomTemplate.setAusleseBackgroundContent(schemeEditVo.getAusleseBackgroundContent());
        agedmallCustomTemplate.setAusleseBackgroundImage(schemeEditVo.getAusleseBackgroundImage());
        agedmallCustomTemplateMapper.updateByPrimaryKeySelective(agedmallCustomTemplate);
        return ResponseUtil.ok();
    }

    public Object schemeDel(String schemeId) {
        JSONObject jsonObject = JSON.parseObject(schemeId);
        Integer sid = Integer.parseInt(jsonObject.get("schemeId").toString());
        AgedmallAgentExample agedmallAgentExample = new AgedmallAgentExample();
        agedmallAgentExample.or().andDeletedEqualTo(false).andPromotionSchemeEqualTo(sid.longValue());
        List<AgedmallAgent> agedmallAgents = agedmallAgentMapper.selectByExample(agedmallAgentExample);
        if (!agedmallAgents.isEmpty()) {
            return ResponseUtil.fail(1203, "推广方案已被绑定");
        }
        agedmallCustomTemplateMapper.logicalDeleteByPrimaryKey(sid);
        return ResponseUtil.ok();
    }

    public Object extensionList(ExtensionListVo extensionListVo) {
        Page page = PageHelper.startPage(extensionListVo.getPage(), extensionListVo.getLimit());
        List<CustomGoodsListDto> customGoodsListDtos = agedmallShopMapper.selectCustomGoodsList(extensionListVo.getShopId(),
                extensionListVo.getCommdityType(), extensionListVo.getCommditySubType(), extensionListVo.getCommdityState(), extensionListVo.getKeySearch());
        Map<String, Object> map = new HashMap<>();
        map.put("total", page.getTotal());
        map.put("data", customGoodsListDtos);
        return ResponseUtil.ok(map);
    }

    public Object unExtensionList(UnextensionListVo unextensionListVo) {
        Page page = PageHelper.startPage(unextensionListVo.getPage(), unextensionListVo.getLimit());
        List<CustomGoodsListDto> customGoodsListDtos = agedmallShopMapper.selectUnCustomGoodsList(unextensionListVo.getShopId()
                , unextensionListVo.getCommdityType(), unextensionListVo.getCommditySubType()
                , unextensionListVo.getCommdityState(), unextensionListVo.getKeySearch());
        Map<String, Object> map = new HashMap<>();
        map.put("total", page.getTotal());
        map.put("data", customGoodsListDtos);
        return ResponseUtil.ok(map);
    }

    public Object extensionCancel(List<Integer> commodityId) {
        for (int i = 0; i < commodityId.size(); i++) {
            List<AgedmallCustomTemplate> agedmallCustomTemplates = agedmallShopMapper.selectCustomGoodsListByGoodsId(commodityId.get(i).toString());
            if (!agedmallCustomTemplates.isEmpty()) {
                return ResponseUtil.fail(611, "商品已在推广方案中使用");
            }

//            List<AgedmallCustomTemplate> needChangeCustomList = new ArrayList<>();
//            for (int j = 0; j < agedmallCustomTemplates.size(); j++) {
//                AgedmallCustomTemplate customTemplate = agedmallCustomTemplates.get(j);
//                String[] goodss = customTemplate.getCanCustomGoods().split(",");
//                ArrayList<String> arrayList = new ArrayList<>(goodss.length);
//                Collections.addAll(arrayList, goodss);
//                if (customTemplate.getCanCustomGoodsType() != 2) {
//                    arrayList.remove(commodityId.get(i).toString());
//                } else {
//                    arrayList.add(commodityId.get(i).toString());
//                }
//                String backGoods = StringUtils.join(arrayList.toArray(), ",");
//                customTemplate.setCanCustomGoods(backGoods);
//                needChangeCustomList.add(customTemplate);
//            }
//            agedmallShopMapper.updateCustomTemplateBatch(needChangeCustomList);
        }
        AgedmallCustomGoodsExample goodsExample = new AgedmallCustomGoodsExample();
        goodsExample.or().andGoodsIdIn(commodityId);
        agedmallCustomGoodsMapper.logicalDeleteByExample(goodsExample);
        return ResponseUtil.ok();
    }


    public Object promotionUpdateProportion(List<PromotionUpdateProportionVo> pupv) {


        List<AgedmallCustomGoods> customGoods = new ArrayList<>();
        for (int i = 0; i < pupv.size(); i++) {
            AgedmallCustomGoodsExample customGoodsExample = new AgedmallCustomGoodsExample();
            customGoodsExample.or().andGoodsIdEqualTo(pupv.get(i).getGoodsId()).andBusIdEqualTo(pupv.get(i).getShopId().longValue()).andDeletedEqualTo(false);
            List<AgedmallCustomGoods> updateGoodsList = agedmallCustomGoodsMapper.selectByExample(customGoodsExample);
            if (updateGoodsList.size() > 0) {
                AgedmallCustomGoods updateGoods = updateGoodsList.get(0);
                updateGoods.setGoodsId(pupv.get(i).getGoodsId());
                updateGoods.setConsumptionType(pupv.get(i).getType());
                if (pupv.get(i).getType() == 0) {
                    updateGoods.setConsumptionPrice(pupv.get(i).getProportion());
                } else {
                    updateGoods.setConsumptionPrice(pupv.get(i).getFixed());
                }
                updateGoods.setBusId(pupv.get(i).getShopId().longValue());
                agedmallCustomGoodsMapper.updateByPrimaryKeySelective(updateGoods);
            } else {
                AgedmallCustomGoods agedmallCustomGoods = new AgedmallCustomGoods();
                agedmallCustomGoods.setGoodsId(pupv.get(i).getGoodsId());
                agedmallCustomGoods.setConsumptionType(pupv.get(i).getType());
                if (pupv.get(i).getType() == 0) {
                    agedmallCustomGoods.setConsumptionPrice(pupv.get(i).getProportion());
                } else {
                    agedmallCustomGoods.setConsumptionPrice(pupv.get(i).getFixed());
                }
                agedmallCustomGoods.setBusId(pupv.get(i).getShopId().longValue());
                agedmallCustomGoods.setAddTime(LocalDateTime.now());
                customGoods.add(agedmallCustomGoods);
            }
        }
        if (customGoods.size() > 0) {
            agedmallShopMapper.insertCustomGoodsBatch(customGoods);
        }
        return ResponseUtil.ok();
    }

    public Object promotionUpdate(PromotionUpdateVo promotionUpdateVo) {
        String[] goodsIds = promotionUpdateVo.getGoodsId().split(",");
        List<Integer> customGoodsId = new ArrayList<>();
        for (int i = 0; i < goodsIds.length; i++) {
            customGoodsId.add(Integer.parseInt(goodsIds[i]));
        }
        AgedmallCustomGoodsExample goodsExample = new AgedmallCustomGoodsExample();
        goodsExample.or().andGoodsIdIn(customGoodsId);
        List<AgedmallCustomGoods> customGoods = agedmallCustomGoodsMapper.selectByExample(goodsExample);
        List<AgedmallCustomGoods> updateGoodsList = new ArrayList<>();
        for (int i = 0; i < customGoods.size(); i++) {
            AgedmallCustomGoods backGoods = customGoods.get(i);
            backGoods.setConsumptionType(promotionUpdateVo.getType());
            backGoods.setConsumptionPrice(promotionUpdateVo.getPromotion());
            updateGoodsList.add(backGoods);
        }
        if (customGoods.size() > 0) {
            agedmallShopMapper.updateCustomGoodsBatch(updateGoodsList);
        }
        return ResponseUtil.ok();
    }


    public Object freightTemplateAdd(AddExpressVo addExpressVo) {
        AgedmallFreightTemplate agedmallFreightTemplat = new AgedmallFreightTemplate();
        AgedmallFreightTemplateExample freightTemplateExample = new AgedmallFreightTemplateExample();
        freightTemplateExample.or().andNameEqualTo(addExpressVo.getTemplateName()).andTypeEqualTo(0).andDeletedEqualTo(false);
        AgedmallFreightTemplate isUseFreight = agedmallFreightTemplateMapper.selectOneByExample(freightTemplateExample);
        if (ObjectUtil.isNotNull(isUseFreight)) {
            return ResponseUtil.fail(612, "名称重复");
        }
        agedmallFreightTemplat.setName(addExpressVo.getTemplateName());
        agedmallFreightTemplat.setBusId(addExpressVo.getShopId().longValue());
        agedmallFreightTemplat.setType(0);
        agedmallFreightTemplat.setPayType(addExpressVo.getBillingMethod());
        agedmallFreightTemplat.setExpressTemplate(JSON.toJSONString(addExpressVo.getBistributionArea()));
        agedmallFreightTemplat.setAddTime(LocalDateTime.now());
        agedmallFreightTemplateMapper.insertSelective(agedmallFreightTemplat);
        return ResponseUtil.ok();
    }

    public Object freightTemplateAddSameCity(AddSameCityVo addSameCityVo) {
        AgedmallFreightTemplate agedmallFreightTemplat = new AgedmallFreightTemplate();
        AgedmallFreightTemplateExample freightTemplateExample = new AgedmallFreightTemplateExample();
        freightTemplateExample.or().andNameEqualTo(addSameCityVo.getTemplateName()).andTypeEqualTo(1).andDeletedEqualTo(false);
        AgedmallFreightTemplate isUseFreight = agedmallFreightTemplateMapper.selectOneByExample(freightTemplateExample);
        if (ObjectUtil.isNotNull(isUseFreight)) {
            return ResponseUtil.fail(612, "名称重复");
        }
        agedmallFreightTemplat.setName(addSameCityVo.getTemplateName());
        agedmallFreightTemplat.setBusId(addSameCityVo.getShopId().longValue());
        agedmallFreightTemplat.setType(1);
        agedmallFreightTemplat.setPayType(addSameCityVo.getBillingMethod());
        if (addSameCityVo.getBillingMethod() == 1) {
            agedmallFreightTemplat.setDeliveryRange(addSameCityVo.getDistributionArea().getKilometers());
            agedmallFreightTemplat.setFixedPay(addSameCityVo.getDistributionArea().getCharge());
        } else {
            agedmallFreightTemplat.setSameCityFirstUnit(addSameCityVo.getDistributionArea().getKilometers());
            agedmallFreightTemplat.setSameCityFirstUnitPay(addSameCityVo.getDistributionArea().getCharge());
            agedmallFreightTemplat.setSameCityAfterUnit(addSameCityVo.getDistributionArea().getiKilometers());
            agedmallFreightTemplat.setSameCityAfterUnitPay(addSameCityVo.getDistributionArea().getiCharge());
            agedmallFreightTemplat.setDeliveryRange(addSameCityVo.getDistributionArea().getSupport());
        }
        agedmallFreightTemplat.setAdditionalPayType(addSameCityVo.getWeight().getType());
        agedmallFreightTemplat.setWeight(addSameCityVo.getWeight().getExtra());
        agedmallFreightTemplat.setWeightAfterUnit(addSameCityVo.getWeight().getAddCharges());
        agedmallFreightTemplat.setWeightAfterUnitPay(addSameCityVo.getWeight().getIncrease());
        agedmallFreightTemplat.setCanAppointment(addSameCityVo.getDistri());
        agedmallFreightTemplat.setCanUrgent(addSameCityVo.getButionMode());
        agedmallFreightTemplat.setSendFastestTime(addSameCityVo.getFastTime());
        agedmallFreightTemplat.setSendSlowestTime(addSameCityVo.getSlowTime());

//        agedmallFreightTemplat.setLng(addSameCityVo.getLatitudeAndLongitude()[0]);
//        agedmallFreightTemplat.setLat(addSameCityVo.getLatitudeAndLongitude()[1]);
        if (addSameCityVo.getDistri() == 1) {
            agedmallFreightTemplat.setCanAppointmentType(addSameCityVo.getMana());
            List<TimePeriod> timePeriods = addSameCityVo.getTimePeriod();
            for (int i = 0; i < timePeriods.size(); i++) {
                timePeriods.get(i).setId(i);
            }
            agedmallFreightTemplat.setCanAppointmentTime(JSON.toJSONString(timePeriods));
        }
        if (addSameCityVo.getButionMode() == 1) {
            agedmallFreightTemplat.setUrgentPay(addSameCityVo.getSpeedUp().getUrgent());
            agedmallFreightTemplat.setEarlyUrgentPay(addSameCityVo.getSpeedUp().getUrgentTime());
            agedmallFreightTemplat.setLastUrgentPay(addSameCityVo.getSpeedUp().getTimeInterval());
        }
        agedmallFreightTemplat.setAddTime(LocalDateTime.now());
        agedmallFreightTemplateMapper.insertSelective(agedmallFreightTemplat);
        return ResponseUtil.ok();
    }

    public Object freightTemplateKedit(AddExpressVo addExpressVo) {
        AgedmallFreightTemplate agedmallFreightTemplat = agedmallFreightTemplateMapper.selectByPrimaryKey(addExpressVo.getTemplateID().longValue());
        AgedmallFreightTemplateExample freightTemplateExample = new AgedmallFreightTemplateExample();
        freightTemplateExample.or().andNameEqualTo(addExpressVo.getTemplateName()).andTypeEqualTo(0).andDeletedEqualTo(false);
        AgedmallFreightTemplate isUseFreight = agedmallFreightTemplateMapper.selectOneByExample(freightTemplateExample);
        if (ObjectUtil.isNotNull(isUseFreight) && !agedmallFreightTemplat.getName().equals(addExpressVo.getTemplateName())) {
            return ResponseUtil.fail(612, "名称重复");
        }
        agedmallFreightTemplat.setName(addExpressVo.getTemplateName());
        agedmallFreightTemplat.setBusId(addExpressVo.getShopId().longValue());
        agedmallFreightTemplat.setType(0);
        agedmallFreightTemplat.setPayType(addExpressVo.getBillingMethod());
        agedmallFreightTemplat.setExpressTemplate(JSON.toJSONString(addExpressVo.getBistributionArea()));
        agedmallFreightTemplateMapper.updateByPrimaryKeySelective(agedmallFreightTemplat);
        return ResponseUtil.ok();
    }


    public Object freightTemplateTedit(AddSameCityVo addSameCityVo) {
        AgedmallFreightTemplate agedmallFreightTemplat = agedmallFreightTemplateMapper.selectByPrimaryKey(addSameCityVo.getTemplateID().longValue());
        AgedmallFreightTemplateExample freightTemplateExample = new AgedmallFreightTemplateExample();
        freightTemplateExample.or().andNameEqualTo(addSameCityVo.getTemplateName()).andTypeEqualTo(1).andDeletedEqualTo(false);
        AgedmallFreightTemplate isUseFreight = agedmallFreightTemplateMapper.selectOneByExample(freightTemplateExample);
        if (ObjectUtil.isNotNull(isUseFreight) && !agedmallFreightTemplat.getName().equals(addSameCityVo.getTemplateName())) {
            return ResponseUtil.fail(612, "名称重复");
        }
        agedmallFreightTemplat.setName(addSameCityVo.getTemplateName());
        agedmallFreightTemplat.setBusId(addSameCityVo.getShopId().longValue());
        agedmallFreightTemplat.setType(1);
        agedmallFreightTemplat.setPayType(addSameCityVo.getBillingMethod());
        if (addSameCityVo.getBillingMethod() == 1) {
            agedmallFreightTemplat.setDeliveryRange(addSameCityVo.getDistributionArea().getKilometers());
            agedmallFreightTemplat.setFixedPay(addSameCityVo.getDistributionArea().getCharge());
        } else {
            agedmallFreightTemplat.setSameCityFirstUnit(addSameCityVo.getDistributionArea().getKilometers());
            agedmallFreightTemplat.setSameCityFirstUnitPay(addSameCityVo.getDistributionArea().getCharge());
            agedmallFreightTemplat.setSameCityAfterUnit(addSameCityVo.getDistributionArea().getiKilometers());
            agedmallFreightTemplat.setSameCityAfterUnitPay(addSameCityVo.getDistributionArea().getiCharge());
            agedmallFreightTemplat.setDeliveryRange(addSameCityVo.getDistributionArea().getSupport());
        }
        agedmallFreightTemplat.setAdditionalPayType(addSameCityVo.getWeight().getType());
        agedmallFreightTemplat.setWeight(addSameCityVo.getWeight().getExtra());
        agedmallFreightTemplat.setWeightAfterUnit(addSameCityVo.getWeight().getAddCharges());
        agedmallFreightTemplat.setWeightAfterUnitPay(addSameCityVo.getWeight().getIncrease());
        agedmallFreightTemplat.setCanAppointment(addSameCityVo.getDistri());
        agedmallFreightTemplat.setCanUrgent(addSameCityVo.getButionMode());
        agedmallFreightTemplat.setSendFastestTime(addSameCityVo.getFastTime());
        agedmallFreightTemplat.setSendSlowestTime(addSameCityVo.getSlowTime());

//        agedmallFreightTemplat.setLng(addSameCityVo.getLatitudeAndLongitude()[0]);
//        agedmallFreightTemplat.setLat(addSameCityVo.getLatitudeAndLongitude()[1]);
        if (addSameCityVo.getDistri() == 1) {
            agedmallFreightTemplat.setCanAppointmentType(addSameCityVo.getMana());
            List<TimePeriod> timePeriods = addSameCityVo.getTimePeriod();
            for (int i = 0; i < timePeriods.size(); i++) {
                timePeriods.get(i).setId(i);
            }
            agedmallFreightTemplat.setCanAppointmentTime(JSON.toJSONString(addSameCityVo.getTimePeriod()));
        }
        if (addSameCityVo.getButionMode() == 1) {
            agedmallFreightTemplat.setUrgentPay(addSameCityVo.getSpeedUp().getUrgent());
            agedmallFreightTemplat.setEarlyUrgentPay(addSameCityVo.getSpeedUp().getUrgentTime());
            agedmallFreightTemplat.setLastUrgentPay(addSameCityVo.getSpeedUp().getTimeInterval());
        }
        agedmallFreightTemplateMapper.updateByPrimaryKeySelective(agedmallFreightTemplat);
        return ResponseUtil.ok();
    }


    public Object freightTemplateList(FreightTemplateListVo freightTemplateListVo) {
        Page page = PageHelper.startPage(freightTemplateListVo.getPage(), freightTemplateListVo.getLimit());
        List<FreightTemplateDto> freightTemplateDtos = agedmallShopMapper.selectFreightTemplateListByType(
                freightTemplateListVo.getType(), freightTemplateListVo.getKeySearch(), freightTemplateListVo.getShopId());
        Map<String, Object> map = new HashMap<>();
        map.put("total", page.getTotal());
        map.put("data", freightTemplateDtos);
        return ResponseUtil.ok(map);
    }

    public Object freightTemplateDel(String templateID) {
        JSONObject jsonObject = JSON.parseObject(templateID);
        Integer sid = Integer.parseInt(jsonObject.get("templateID").toString());
        AgedmallStoreGoodsExample goodsExample = new AgedmallStoreGoodsExample();
        goodsExample.or().andLogisticsTypeEqualTo((byte) 1).andExpressEqualTo(sid.longValue()).andDeletedEqualTo(false);
        List<AgedmallStoreGoods> agedmallStoreGoods = agedmallStoreGoodsMapper.selectByExample(goodsExample);

        AgedmallStoreGoodsExample sameCityGoodsExample = new AgedmallStoreGoodsExample();
        sameCityGoodsExample.or().andLogisticsTypeEqualTo((byte) 1).andSameCityEqualTo(sid.longValue()).andDeletedEqualTo(false);
        List<AgedmallStoreGoods> sameCityStoreGoods = agedmallStoreGoodsMapper.selectByExample(sameCityGoodsExample);

        if (!agedmallStoreGoods.isEmpty() || !sameCityStoreGoods.isEmpty()) {
            return ResponseUtil.fail(1100, "模板已被使用");
        }
        agedmallFreightTemplateMapper.logicalDeleteByPrimaryKey(sid.longValue());
        return ResponseUtil.ok();
    }

    public Object collectMoneyTemplateAdd(CollectMoneyTemplateAddVo collectMoneyTemplateAddVo) {
        AgedmallChargeTemplateExample chargeTemplateExample = new AgedmallChargeTemplateExample();
        chargeTemplateExample.or().andNameEqualTo(collectMoneyTemplateAddVo.getTemplateName()).andDeletedEqualTo(false);
        List<AgedmallChargeTemplate> agedmallChargeTemplates = agedmallChargeTemplateMapper.selectByExample(chargeTemplateExample);
        if (agedmallChargeTemplates != null && !agedmallChargeTemplates.isEmpty()) {
            return ResponseUtil.fail(645, "模板名称已经存在");
        }
        AgedmallChargeTemplate agedmallChargeTemplate = new AgedmallChargeTemplate();
        agedmallChargeTemplate.setName(collectMoneyTemplateAddVo.getTemplateName());
        agedmallChargeTemplate.setBusId(collectMoneyTemplateAddVo.getShopId().longValue());
        agedmallChargeTemplate.setRemark(collectMoneyTemplateAddVo.getRemarks());
        agedmallChargeTemplate.setTopPriceType(collectMoneyTemplateAddVo.getCappinCharge());
        agedmallChargeTemplate.setTopPrice(collectMoneyTemplateAddVo.getCustomPrice());
        agedmallChargeTemplate.setAddTime(LocalDateTime.now());
        agedmallChargeTemplate.setDeleted(false);
        agedmallChargeTemplateMapper.insert(agedmallChargeTemplate);
        addChargeTemplateLeasePeriod(collectMoneyTemplateAddVo.getCollectModelList(),agedmallChargeTemplate.getId());
        return ResponseUtil.ok();
    }

    public void addChargeTemplateLeasePeriod(List<BasicCharge> collectModelList,Integer templateId){
        List<AgedmallChargeTemplateLeasePeriod> chargeTemplateLeasePeriodList=new ArrayList<>();
        for (int i = 0; i < collectModelList.size(); i++) {
            AgedmallChargeTemplateLeasePeriod leasePeriod=new AgedmallChargeTemplateLeasePeriod();
            leasePeriod.setAddTime(LocalDateTime.now());
            leasePeriod.setCustomTemplateId(templateId);
            leasePeriod.setBaseDay(collectModelList.get(i).getStartRentDay());
            leasePeriod.setBasePrice(collectModelList.get(i).getUnitPrice());
            leasePeriod.setLadderPrice(ladderPriceFormat(collectModelList.get(i).getLadderCharge()));
            chargeTemplateLeasePeriodList.add(leasePeriod);
        }
        agedmallShopMapper.insertLeasePeriodList(chargeTemplateLeasePeriodList);
    }

    public String ladderPriceFormat(List<LadderCharge> ladderCharge) {
        if (!ladderCharge.isEmpty()) {
            List<ChargeLadderPrice> chargeLadderPrices = new ArrayList<>();
            for (int i = 0; i < ladderCharge.size(); i++) {
                ChargeLadderPrice chargeLadderPrice = new ChargeLadderPrice();
                chargeLadderPrice.setPrice(ladderCharge.get(i).getPrice());
                chargeLadderPrice.setBegin(ladderCharge.get(i).getBegin());
                if (i + 1 == ladderCharge.size()) {
                    chargeLadderPrice.setEnd(99999);
                } else {
                    chargeLadderPrice.setEnd(ladderCharge.get(i + 1).getBegin() - 1);
                }
                chargeLadderPrices.add(chargeLadderPrice);
            }
            return JSON.toJSONString(chargeLadderPrices);
        }
        return null;
    }

    public Object collectMoneyTemplateEdit(CollectMoneyTemplateAddVo collectMoneyTemplateAddVo) {
        AgedmallChargeTemplate agedmallChargeTemplate = agedmallChargeTemplateMapper.selectByPrimaryKey(collectMoneyTemplateAddVo.getTemplateId());
        AgedmallChargeTemplateExample chargeTemplateExample = new AgedmallChargeTemplateExample();
        chargeTemplateExample.or().andNameEqualTo(collectMoneyTemplateAddVo.getTemplateName()).andDeletedEqualTo(false);
        List<AgedmallChargeTemplate> agedmallChargeTemplates = agedmallChargeTemplateMapper.selectByExample(chargeTemplateExample);
        if (agedmallChargeTemplates != null && !agedmallChargeTemplates.isEmpty()
                && !agedmallChargeTemplate.getName().equals(collectMoneyTemplateAddVo.getTemplateName())) {
            return ResponseUtil.fail(645, "模板名称已经存在");
        }
        agedmallChargeTemplate.setName(collectMoneyTemplateAddVo.getTemplateName());
        agedmallChargeTemplate.setRemark(collectMoneyTemplateAddVo.getRemarks());
        agedmallChargeTemplate.setTopPriceType(collectMoneyTemplateAddVo.getCappinCharge());
        agedmallChargeTemplate.setTopPrice(collectMoneyTemplateAddVo.getCustomPrice());
        agedmallChargeTemplateMapper.updateByPrimaryKeySelective(agedmallChargeTemplate);
        modifyChargeTemplateLeasePeriod(collectMoneyTemplateAddVo.getCollectModelList(),agedmallChargeTemplate.getId());
        return ResponseUtil.ok();
    }


    public void modifyChargeTemplateLeasePeriod(List<BasicCharge> collectModelList,Integer templateId){
        List<AgedmallChargeTemplateLeasePeriod> addChageTemplateLeasePeriodList=new ArrayList<>();
        List<AgedmallChargeTemplateLeasePeriod> modifyChageTemplateLeasePeriodList=new ArrayList<>();
        AgedmallChargeTemplateLeasePeriodExample leasePeriodExample=new AgedmallChargeTemplateLeasePeriodExample();
        leasePeriodExample.createCriteria().andDeletedEqualTo(false).andCustomTemplateIdEqualTo(templateId);
        List<AgedmallChargeTemplateLeasePeriod> oldLeasePeriodList=agedmallChargeTemplateLeasePeriodMapper.selectByExample(leasePeriodExample);
        List<Long> oldIdList=new ArrayList<>();
        oldLeasePeriodList.forEach( old -> oldIdList.add(old.getId()));

        for (int i = 0; i < collectModelList.size(); i++) {
            //新增
            if(collectModelList.get(i).getId()==null){
                AgedmallChargeTemplateLeasePeriod leasePeriod=new AgedmallChargeTemplateLeasePeriod();
                leasePeriod.setAddTime(LocalDateTime.now());
                leasePeriod.setCustomTemplateId(templateId);
                leasePeriod.setBaseDay(collectModelList.get(i).getStartRentDay());
                leasePeriod.setBasePrice(collectModelList.get(i).getUnitPrice());
                leasePeriod.setLadderPrice(ladderPriceFormat(collectModelList.get(i).getLadderCharge()));
                addChageTemplateLeasePeriodList.add(leasePeriod);
            }
            //修改
            else if(collectModelList.get(i).getId()!=null&&oldIdList.contains(collectModelList.get(i).getId())){
                AgedmallChargeTemplateLeasePeriod leasePeriod=new AgedmallChargeTemplateLeasePeriod();
                leasePeriod.setId(collectModelList.get(i).getId());
                leasePeriod.setCustomTemplateId(templateId);
                leasePeriod.setBaseDay(collectModelList.get(i).getStartRentDay());
                leasePeriod.setBasePrice(collectModelList.get(i).getUnitPrice());
                leasePeriod.setLadderPrice(ladderPriceFormat(collectModelList.get(i).getLadderCharge()));
                modifyChageTemplateLeasePeriodList.add(leasePeriod);
            }
            //删除
            else{
                agedmallChargeTemplateLeasePeriodMapper.logicalDeleteByPrimaryKey(collectModelList.get(i).getId());
            }
        }

        if(addChageTemplateLeasePeriodList!=null&&addChageTemplateLeasePeriodList.size()>0){
            agedmallShopMapper.insertLeasePeriodList(addChageTemplateLeasePeriodList);
        }
        if(modifyChageTemplateLeasePeriodList!=null&&modifyChageTemplateLeasePeriodList.size()>0){
            agedmallShopMapper.updateLeasePeriodList(modifyChageTemplateLeasePeriodList);
        }
    }

    public Object collectMoneyTemplateList(CollectMoneyTemplateListVo collectMoneyTemplateAddVo) {
        Page page = PageHelper.startPage(collectMoneyTemplateAddVo.getPage(), collectMoneyTemplateAddVo.getLimit());
        List<ChargeTemplateDto> chargeTemplateDtos = agedmallShopMapper.selectChargeTemplateList(
                collectMoneyTemplateAddVo.getKeySearch(), collectMoneyTemplateAddVo.getShopId());

        for (int i = 0; i < chargeTemplateDtos.size(); i++) {
            AgedmallChargeTemplateLeasePeriodExample leasePeriodExample=new AgedmallChargeTemplateLeasePeriodExample();
            leasePeriodExample.createCriteria().andDeletedEqualTo(false).andCustomTemplateIdEqualTo(chargeTemplateDtos.get(i).getId());
            List<AgedmallChargeTemplateLeasePeriod> oldLeasePeriodList=agedmallChargeTemplateLeasePeriodMapper.selectByExampleWithBLOBs(leasePeriodExample);
            chargeTemplateDtos.get(i).setCollectModelList(oldLeasePeriodList);
        }

        Map<String, Object> map = new HashMap<>();
        map.put("total", page.getTotal());
        map.put("data", chargeTemplateDtos);
        return ResponseUtil.ok(map);
    }

    public Object collectMoneyTemplateDel(List<Integer> ids) {
        AgedmallStoreGoodsExample goodsExample = new AgedmallStoreGoodsExample();
        goodsExample.or().andLeaseChargeTemplateIdIn(ids);
        List<AgedmallStoreGoods> agedmallStoreGoods = agedmallStoreGoodsMapper.selectByExample(goodsExample);
        if (!agedmallStoreGoods.isEmpty()) {
            return ResponseUtil.fail(1100, "模板已被使用");
        }
        AgedmallChargeTemplateExample chargeTemplateExample = new AgedmallChargeTemplateExample();
        chargeTemplateExample.or().andIdIn(ids).andDeletedEqualTo(false);
        agedmallChargeTemplateMapper.logicalDeleteByExample(chargeTemplateExample);
        return ResponseUtil.ok();
    }

    public Object ywfTemplateAdd(YWFTemplateAddVo ywfTemplateAddVo) {
        AgedmallMaintainTemplate agedmallMaintainTemplate = new AgedmallMaintainTemplate();
        AgedmallMaintainTemplateExample maintainTemplateExample = new AgedmallMaintainTemplateExample();
        maintainTemplateExample.or().andNameEqualTo(ywfTemplateAddVo.getTemplateName()).andDeletedEqualTo(false).andBusIdEqualTo(ywfTemplateAddVo.getShopId().longValue());
        AgedmallMaintainTemplate isUseMainTain = agedmallMaintainTemplateMapper.selectOneByExample(maintainTemplateExample);
        if (ObjectUtil.isNotNull(isUseMainTain)) {
            return ResponseUtil.fail(612, "名称重复");
        }
        agedmallMaintainTemplate.setName(ywfTemplateAddVo.getTemplateName());
        agedmallMaintainTemplate.setType(ywfTemplateAddVo.getCommodityType());
        agedmallMaintainTemplate.setDistributionPrice(ywfTemplateAddVo.getpHuo());
        agedmallMaintainTemplate.setDeliveryPrice(ywfTemplateAddVo.getpSong());
        agedmallMaintainTemplate.setMaintainPrice(ywfTemplateAddVo.getpWihu());
        agedmallMaintainTemplate.setAddTime(LocalDateTime.now());
        agedmallMaintainTemplate.setBusId(ywfTemplateAddVo.getShopId().longValue());
        agedmallMaintainTemplateMapper.insertSelective(agedmallMaintainTemplate);
        return ResponseUtil.ok();
    }

    public Object ywfTemplateEdit(YWFTemplateAddVo ywfTemplateAddVo) {
        AgedmallMaintainTemplate agedmallMaintainTemplate = agedmallMaintainTemplateMapper.selectByPrimaryKey(ywfTemplateAddVo.getTemplateId());
        AgedmallMaintainTemplateExample maintainTemplateExample = new AgedmallMaintainTemplateExample();
        maintainTemplateExample.or().andNameEqualTo(ywfTemplateAddVo.getTemplateName()).andDeletedEqualTo(false).andBusIdEqualTo(ywfTemplateAddVo.getShopId().longValue());
        AgedmallMaintainTemplate isUseMainTain = agedmallMaintainTemplateMapper.selectOneByExample(maintainTemplateExample);
        if (ObjectUtil.isNotNull(isUseMainTain) && !agedmallMaintainTemplate.getName().equals(ywfTemplateAddVo.getTemplateName())) {
            return ResponseUtil.fail(612, "名称重复");
        }
        agedmallMaintainTemplate.setName(ywfTemplateAddVo.getTemplateName());
        agedmallMaintainTemplate.setType(ywfTemplateAddVo.getCommodityType());
        agedmallMaintainTemplate.setDistributionPrice(ywfTemplateAddVo.getpHuo());
        agedmallMaintainTemplate.setDeliveryPrice(ywfTemplateAddVo.getpSong());
        agedmallMaintainTemplate.setMaintainPrice(ywfTemplateAddVo.getpWihu());
        agedmallMaintainTemplateMapper.updateByPrimaryKeySelective(agedmallMaintainTemplate);
        return ResponseUtil.ok();
    }


    public Object ywfTemplateList(YWFTemplateListVo ywfTemplateListVo) {
        Page page = PageHelper.startPage(ywfTemplateListVo.getPage(), ywfTemplateListVo.getLimit());
        List<MaintainTemplateDto> maintainTemplateDtos = agedmallShopMapper.selectMaintainTemplateList(
                ywfTemplateListVo.getShopId(), ywfTemplateListVo.getKeySearch(), ywfTemplateListVo.getType());
        Map<String, Object> map = new HashMap<>();
        map.put("total", page.getTotal());
        map.put("data", maintainTemplateDtos);
        return ResponseUtil.ok(map);
    }


    public Object ywfTemplateDel(String id) {
        JSONObject jsonObject = JSON.parseObject(id);
        Integer sid = Integer.parseInt(jsonObject.get("id").toString());
        AgedmallStoreGoodsExample goodsExample = new AgedmallStoreGoodsExample();
        goodsExample.or().andMaintainTemplateIdEqualTo(sid.longValue());
        List<AgedmallStoreGoods> agedmallStoreGoods = agedmallStoreGoodsMapper.selectByExample(goodsExample);
        if (!agedmallStoreGoods.isEmpty()) {
            return ResponseUtil.fail(1100, "模板已被使用");
        }
        agedmallMaintainTemplateMapper.logicalDeleteByPrimaryKey(sid);
        return ResponseUtil.ok();
    }


    public Object gloudWarehouseAdd(GloudWarehouseAddVo gloudWarehouseAddVo) {
        AgedmallCloudHouse agedmallCloudHouse = new AgedmallCloudHouse();
        AgedmallCloudHouseExample cloudHouseExample = new AgedmallCloudHouseExample();
        cloudHouseExample.or().andNameEqualTo(gloudWarehouseAddVo.getWarehouseName()).andDeletedEqualTo(false);
        AgedmallCloudHouse isUseNameCloud = agedmallCloudHouseMapper.selectOneByExample(cloudHouseExample);
        if (ObjectUtil.isNotNull(isUseNameCloud)) {
            return ResponseUtil.fail(612, "名称重复");
        }
        agedmallCloudHouse.setAddTime(LocalDateTime.now());
        agedmallCloudHouse.setName(gloudWarehouseAddVo.getWarehouseName());
        agedmallCloudHouse.setBusId(gloudWarehouseAddVo.getShopId());
        agedmallCloudHouse.setProvinceId(gloudWarehouseAddVo.getProvinceID());
        agedmallCloudHouse.setProvince(gloudWarehouseAddVo.getProvinceName());
        agedmallCloudHouse.setCityId(gloudWarehouseAddVo.getCityID());
        agedmallCloudHouse.setCity(gloudWarehouseAddVo.getCityName());
        agedmallCloudHouse.setVillageId(gloudWarehouseAddVo.getAreaID());
        agedmallCloudHouse.setVillage(gloudWarehouseAddVo.getAreaName());
        agedmallCloudHouse.setLng(gloudWarehouseAddVo.getLatitudeAndLongitude().get(0));
        agedmallCloudHouse.setLat(gloudWarehouseAddVo.getLatitudeAndLongitude().get(1));
        agedmallCloudHouse.setAddressDetail(gloudWarehouseAddVo.getDetailAddress());
        agedmallCloudHouseMapper.insertSelective(agedmallCloudHouse);
        return ResponseUtil.ok();
    }


    public Object gloudWarehouseEditUpdate(GloudWarehouseAddVo gloudWarehouseAddVo) {
        AgedmallCloudHouse agedmallCloudHouse = agedmallCloudHouseMapper.selectByPrimaryKey(gloudWarehouseAddVo.getId());
        AgedmallCloudHouseExample cloudHouseExample = new AgedmallCloudHouseExample();
        cloudHouseExample.or().andNameEqualTo(gloudWarehouseAddVo.getWarehouseName()).andDeletedEqualTo(false);
        AgedmallCloudHouse isUseNameCloud = agedmallCloudHouseMapper.selectOneByExample(cloudHouseExample);
        if (ObjectUtil.isNotNull(isUseNameCloud) && !agedmallCloudHouse.getName().equals(gloudWarehouseAddVo.getWarehouseName())) {
            return ResponseUtil.fail(612, "名称重复");
        }
        agedmallCloudHouse.setName(gloudWarehouseAddVo.getWarehouseName());
        agedmallCloudHouse.setBusId(gloudWarehouseAddVo.getShopId());
        agedmallCloudHouse.setProvinceId(gloudWarehouseAddVo.getProvinceID());
        agedmallCloudHouse.setProvince(gloudWarehouseAddVo.getProvinceName());
        agedmallCloudHouse.setCityId(gloudWarehouseAddVo.getCityID());
        agedmallCloudHouse.setCity(gloudWarehouseAddVo.getCityName());
        agedmallCloudHouse.setVillageId(gloudWarehouseAddVo.getAreaID());
        agedmallCloudHouse.setVillage(gloudWarehouseAddVo.getAreaName());
        agedmallCloudHouse.setLng(gloudWarehouseAddVo.getLatitudeAndLongitude().get(0));
        agedmallCloudHouse.setLat(gloudWarehouseAddVo.getLatitudeAndLongitude().get(1));
        agedmallCloudHouse.setAddressDetail(gloudWarehouseAddVo.getDetailAddress());
        agedmallCloudHouseMapper.updateByPrimaryKeySelective(agedmallCloudHouse);
        return ResponseUtil.ok();
    }


    public Object gloudWarehouseList(GloudWarehouseListVo gloudWarehouseListVo) {
        AgedmallCloudHouseExample cloudHouseExample = new AgedmallCloudHouseExample();
        cloudHouseExample.or().andNameLike("%" + gloudWarehouseListVo.getKeySearch() + "%")
                .andBusIdEqualTo(gloudWarehouseListVo.getShopId())
                .andDeletedEqualTo(false);
        cloudHouseExample.setOrderByClause("add_time DESC");
        Page page = PageHelper.startPage(gloudWarehouseListVo.getPage(), gloudWarehouseListVo.getLimit());
        List<AgedmallCloudHouse> agedmallCloudHouses = agedmallCloudHouseMapper.selectByExample(cloudHouseExample);
        Map<String, Object> map = new HashMap<>();
        map.put("total", page.getTotal());
        map.put("data", agedmallCloudHouses);
        return ResponseUtil.ok(map);
    }

    public Object gloudWarehouseDel(List<Integer> warehouseId) {
        AgedmallCloudHouseExample cloudHouseExample = new AgedmallCloudHouseExample();
        cloudHouseExample.or().andIdIn(warehouseId);
        agedmallCloudHouseMapper.logicalDeleteByExample(cloudHouseExample);
        return ResponseUtil.ok();
    }


    public Object gloudWarehouseAddCommodity(GloudWarehouseAddCommodityVo gloudWarehouseAddCommodityVo) {

        AgedmallCloudGoodsProductExample cloudGoodsProductExample = new AgedmallCloudGoodsProductExample();
        cloudGoodsProductExample.or().andGoodsIdIn(gloudWarehouseAddCommodityVo.getCommodityId())
                .andCloudIdEqualTo(gloudWarehouseAddCommodityVo.getWarehouseId().longValue());
        List<AgedmallCloudGoodsProduct> cloudGoodsProducts1 = agedmallCloudGoodsProductMapper.selectByExample(cloudGoodsProductExample);
        if (cloudGoodsProducts1.size() > 0) {
            return ResponseUtil.fail(601, "添加的商品已存在于当前云仓");
        }
        LitemallGoodsProductExample goodsProductExample = new LitemallGoodsProductExample();
        List<Integer> goodsIdList = new ArrayList<>();
        for (int i = 0; i < gloudWarehouseAddCommodityVo.getCommodityId().size(); i++) {
            goodsIdList.add(gloudWarehouseAddCommodityVo.getCommodityId().get(i).intValue());
        }
        goodsProductExample.or().andGoodsIdIn(goodsIdList).andDeletedEqualTo(false);
        List<LitemallGoodsProduct> litemallGoodsProducts = litemallGoodsProductMapper.selectByExample(goodsProductExample);
        List<AgedmallCloudGoodsProduct> cloudGoodsProducts = new ArrayList<>();
        for (int i = 0; i < litemallGoodsProducts.size(); i++) {
            AgedmallCloudGoodsProduct goodsProduct = new AgedmallCloudGoodsProduct();
            goodsProduct.setGoodsId(litemallGoodsProducts.get(i).getGoodsId().longValue());
            goodsProduct.setGoodsProductId(litemallGoodsProducts.get(i).getId().longValue());
            goodsProduct.setCloudId(gloudWarehouseAddCommodityVo.getWarehouseId().longValue());
            goodsProduct.setProductStock(0);
            goodsProduct.setAddTime(LocalDateTime.now());
            cloudGoodsProducts.add(goodsProduct);
        }
        agedmallShopMapper.insertCloudGoodsProductBatch(cloudGoodsProducts);
        inventoryUtil.refresh(gloudWarehouseAddCommodityVo.getWarehouseId(), 1);
        return ResponseUtil.ok();
    }

    public Object gloudWarehouseNotInList(GloudWarehouseNotInListVo gwni) {
        Page page = PageHelper.startPage(gwni.getPage(), gwni.getLimit());
        List<NotInCloudGoodsDto> notInCloudGoodsList = agedmallShopMapper.getNotInCloudGoodsList(gwni.getWarehouseId(), gwni.getShopId(), gwni.getCommdityType(),
                gwni.getCommditySubType(), gwni.getCommdityState(), gwni.getKeySearch());
        Map<String, Object> map = new HashMap<>();
        map.put("total", page.getTotal());
        map.put("data", notInCloudGoodsList);
        return ResponseUtil.ok(map);
    }


    public Object gloudWarehouseInventoryManagement(GloudWarehouseInventoryManagementVo gimv) {
        if (gimv.getCommodityType() == null) {
            gimv.setCommodityType(new CommodityType());
        }
        Page page = PageHelper.startPage(gimv.getPage(), gimv.getLimit());
        List<CloudGoodsListVo> cloudGoodsListVos = agedmallShopMapper.selectCloudGoodsList(gimv.getWarehouseId(), gimv.getCommodityType().getTypeOne(),
                gimv.getCommodityType().getTypeTwo(), gimv.getCommodityName(), gimv.getCommodityState());
        Map<String, Object> map = new HashMap<>();
        map.put("total", page.getTotal());
        map.put("data", cloudGoodsListVos);
        return ResponseUtil.ok(map);
    }

    public Object gloudWarehouseModifyMessage(Integer goodsId, Integer cloudId) {
        AgedmallCloudGoodsProductExample cloudGoodsProductExample = new AgedmallCloudGoodsProductExample();
        cloudGoodsProductExample.or().andGoodsIdEqualTo(goodsId.longValue()).andCloudIdEqualTo(cloudId.longValue());
        List<AgedmallCloudGoodsProduct> cloudGoodsProducts = agedmallCloudGoodsProductMapper.selectByExample(cloudGoodsProductExample);

        Map<String, Object> map = (Map<String, Object>) agedmallCommodityService.commodityDetail(goodsId);
        CommodityDetailVo commodityDetailVo = (CommodityDetailVo) map.get("data");
        List<CommodityDetailRegualrForm> newRegualCombo = new ArrayList<>();
        for (int i = 0; i < commodityDetailVo.getRegualrCombo().size(); i++) {
            CommodityDetailRegualrForm commodityDetailRegualrForm = commodityDetailVo.getRegualrCombo().get(i);
            for (int j = 0; j < cloudGoodsProducts.size(); j++) {
                if (commodityDetailRegualrForm.getProductId().longValue() == (cloudGoodsProducts.get(j).getGoodsProductId())) {
                    commodityDetailRegualrForm.setCloudStock(cloudGoodsProducts.get(j).getProductStock());
                    newRegualCombo.add(commodityDetailRegualrForm);
                }
            }
        }
        commodityDetailVo.setRegualrCombo(newRegualCombo);
        return ResponseUtil.ok(commodityDetailVo);
    }

    public Object gloudWarehouseEditWarehouse(GloudWarehouseEditWarehouseVo gwew) {
        List<Long> productsId = new ArrayList<>();
        //最大库存
        Integer maxNumber = 100000;
        Integer nowNumber = 0;
        for (int i = 0; i < gwew.getSpecifications().size(); i++) {
            productsId.add(gwew.getSpecifications().get(i).getId().longValue());
            nowNumber += gwew.getSpecifications().get(i).getWarehouseCount();
        }
        if (nowNumber > maxNumber) {
            return ResponseUtil.fail(669, "商品库存不能大于100000");
        }
        AgedmallCloudGoodsProductExample cloudGoodsProductExample = new AgedmallCloudGoodsProductExample();
        cloudGoodsProductExample.or().andGoodsIdEqualTo(gwew.getCommodityID().longValue()).andCloudIdEqualTo(gwew.getWarehouseId().longValue())
                .andGoodsProductIdIn(productsId);
        List<AgedmallCloudGoodsProduct> cloudGoodsProducts = agedmallCloudGoodsProductMapper.selectByExample(cloudGoodsProductExample);
        List<AgedmallCloudGoodsProduct> updateList = new ArrayList<>();
        for (int i = 0; i < cloudGoodsProducts.size(); i++) {
            AgedmallCloudGoodsProduct cloudGoodsProduct = cloudGoodsProducts.get(i);
            for (int j = 0; j < gwew.getSpecifications().size(); j++) {
                if (cloudGoodsProduct.getGoodsProductId().equals(gwew.getSpecifications().get(j).getId().longValue())) {
                    cloudGoodsProduct.setProductStock(gwew.getSpecifications().get(j).getWarehouseCount());
                    updateList.add(cloudGoodsProduct);
                }
            }
        }
        if (updateList.isEmpty()) {
            return ResponseUtil.fail(666, "更改的商品不存在");
        }
        agedmallShopMapper.updateCloudGoodsProductBatch(updateList);
        inventoryUtil.refresh(gwew.getWarehouseId(), 1);
        return ResponseUtil.ok();
    }

    public Object gloudWarehouseDelWarehouse(DelWarehouseGoodsVo delWarehouseGoodsVo) {
        AgedmallCloudGoodsProductExample cloudGoodsProductExample = new AgedmallCloudGoodsProductExample();
        cloudGoodsProductExample.or().andGoodsIdIn(delWarehouseGoodsVo.getIds()).andCloudIdEqualTo(delWarehouseGoodsVo.getCloudId());
        agedmallCloudGoodsProductMapper.deleteByExample(cloudGoodsProductExample);
        return ResponseUtil.ok();
    }


    public Object gloudWarehouseBatch(GloudWarehouseBatchVo gwbv) {
        String[] goodss = gwbv.getCommotdityId().split(",");
        ArrayList<Integer> arrayList = new ArrayList<>(goodss.length);
        for (int i = 0; i < goodss.length; i++) {
            arrayList.add(Integer.parseInt(goodss[i]));
        }
        agedmallShopMapper.updateCouldGoodsStockBatch(gwbv.getCount(), gwbv.getCloudId(), arrayList);
        inventoryUtil.refresh(gwbv.getCloudId(), 1);
        return ResponseUtil.ok();
    }


    public Object productLabelAdd(ProductLabelAddVo productLabelAddVo) {
        List<AgedmallTags> tagsList = new ArrayList<>();
        long count = productLabelAddVo.getLabelName().stream().distinct().count();
        boolean isRepeat = count < productLabelAddVo.getLabelName().size();
        if (isRepeat) {
            return ResponseUtil.fail(612, "名称重复");
        }
        for (int i = 0; i < productLabelAddVo.getLabelName().size(); i++) {
            AgedmallTagsExample tagsExample = new AgedmallTagsExample();
            tagsExample.or().andNameEqualTo(productLabelAddVo.getLabelName().get(i)).andDeletedEqualTo(false);
            AgedmallTags isNullTags = agedmallTagsMapper.selectOneByExample(tagsExample);
            if (isNullTags != null && isNullTags.getId() != null) {
                return ResponseUtil.fail(612, "名称重复");
            }
            AgedmallTags tags = new AgedmallTags();
            tags.setAddTime(LocalDateTime.now());
            tags.setShowSort(productLabelAddVo.getCommodityOrder());
            tags.setName(productLabelAddVo.getLabelName().get(i));
            tags.setBusId(productLabelAddVo.getShopId());
            tags.setProminent(productLabelAddVo.getProminent());
            tagsList.add(tags);
        }
        agedmallShopMapper.insertTagsBatch(tagsList);
        return ResponseUtil.ok();
    }

    public Object productLabelEdit(ProductLabelEditVo productLabelEditVo) {
        AgedmallTags tags = agedmallTagsMapper.selectByPrimaryKey(productLabelEditVo.getLabelID().longValue());
        AgedmallTagsExample tagsExample = new AgedmallTagsExample();
        tagsExample.or().andNameEqualTo(productLabelEditVo.getLabelName()).andDeletedEqualTo(false);
        AgedmallTags isNullTags = agedmallTagsMapper.selectOneByExample(tagsExample);
        if (ObjectUtil.isNotNull(isNullTags) && !productLabelEditVo.getLabelName().equals(tags.getName())) {
            return ResponseUtil.fail(612, "名称重复");
        }
        tags.setShowSort(productLabelEditVo.getCommodityOrder());
        tags.setName(productLabelEditVo.getLabelName());
        tags.setProminent(productLabelEditVo.getProminent());
        tags.setUpdateTime(LocalDateTime.now());
        agedmallTagsMapper.updateByPrimaryKeySelective(tags);

        return ResponseUtil.ok();
    }

    public static boolean isNumeric(String str) {
        Pattern pattern = Pattern.compile("[0-9]*");
        return pattern.matcher(str).matches();
    }

    public Object productLabelList(ProductLabelListVo productLabelListVo) {
        Page page = PageHelper.startPage(productLabelListVo.getPage(), productLabelListVo.getLimit());
        List<TagsGoodsListDto> tagsList = agedmallShopMapper.selectTagsGoodsCount(productLabelListVo.getShopId());
        List<String> goodsTagsDtos = agedmallShopMapper.selectGoodsTags();
        goodsTagsDtos.forEach(tags -> {
            if (StringUtils.isNotBlank(tags)) {
                String[] tagSplit = tags.split(",");
                for (int i = 0; i < tagsList.size(); i++) {
                    for (String tag : tagSplit) {
//                        String subTag=StrUtil.sub(tag.replaceAll(" ",""),1,-1);
                        String subTag = tag.replaceAll(" ", "");
                        if (isNumeric(subTag) && StrUtil.isNotBlank(subTag)) {
                            if (tagsList.get(i).getId().equals(Integer.parseInt(subTag))) {
                                tagsList.get(i).setGoodsCount(tagsList.get(i).getGoodsCount() <= 0 ? 1 : tagsList.get(i).getGoodsCount() + 1);
                            }
                        }
                    }
                }
            }
        });
        //获取在线服务的标签使用数量
        List<OnlineServiceTagsDto> onlineServiceTagsCount = agedmallShopMapper.getOnlineServiceTagsCount();
        for (int i = 0; i < tagsList.size(); i++) {
            for (int j = 0; j < onlineServiceTagsCount.size(); j++) {
                if (tagsList.get(i).getId().equals(onlineServiceTagsCount.get(j).getId())) {
                    Integer goodsCount = tagsList.get(i).getGoodsCount() == null ? 0 : tagsList.get(i).getGoodsCount();
                    Integer onlineCount = onlineServiceTagsCount.get(j).getOnlineCount() == null ? 0 : onlineServiceTagsCount.get(j).getOnlineCount();
                    tagsList.get(i).setGoodsCount(goodsCount + onlineCount);
                }
            }
        }
        Map<String, Object> map = new HashMap<>();
        map.put("total", page.getTotal());
        map.put("data", tagsList);
        return ResponseUtil.ok(map);
    }

    public Object productLabelDel(List<Long> labelID) {
        for (int i = 0; i < labelID.size(); i++) {
            List<AgedmallOnlineService> agedmallOnlineServices = agedmallShopMapper.selectTagsUseInOnlineService(labelID.get(i).toString());
            if (!agedmallOnlineServices.isEmpty()) {
                return ResponseUtil.fail(630, "标签已被使用,无法删除");
            }
        }
        List<TagsGoodsListDto> tagsList = agedmallShopMapper.selectTagsGoodsCount(null);
        List<String> goodsTagsDtos = agedmallShopMapper.selectGoodsTags();
        goodsTagsDtos.forEach(tags -> {
            if (StringUtils.isNotBlank(tags)) {
                String[] tagSplit = tags.split(",");
                for (int i = 0; i < tagsList.size(); i++) {
                    for (String tag : tagSplit) {
//                        String subTag=StrUtil.sub(tag.replaceAll(" ",""),1,-1);
                        String subTag = tag.replaceAll(" ", "");
                        if (isNumeric(subTag) && StrUtil.isNotBlank(subTag)) {
                            if (tagsList.get(i).getId().equals(Integer.parseInt(subTag))) {
                                tagsList.get(i).setGoodsCount(tagsList.get(i).getGoodsCount() <= 0 ? 1 : tagsList.get(i).getGoodsCount() + 1);
                            }
                        }
                    }
                }
            }
        });
        for (int i = 0; i < tagsList.size(); i++) {
            for (int j = 0; j < labelID.size(); j++) {
                if (tagsList.get(i).getId() == labelID.get(j).intValue() && tagsList.get(i).getGoodsCount() > 0) {
                    return ResponseUtil.fail(630, "标签已被使用,无法删除");
                }
            }
        }
        AgedmallTagsExample agedmallTagsExample = new AgedmallTagsExample();
        agedmallTagsExample.or().andIdIn(labelID);
        agedmallTagsMapper.logicalDeleteByExample(agedmallTagsExample);
        return ResponseUtil.ok();
    }


    public Object shopInformationInfo(Integer shopId) {
        AgedmallBusinessInfo agedmallBusinessInfo = agedmallBusinessInfoMapper.selectByPrimaryKey(shopId);
        return ResponseUtil.ok(agedmallBusinessInfo);
    }

    public Object shopInformationEditStore(ShopInformationEditStoreVo siet) {
        AgedmallBusinessInfo agedmallBusinessInfo = agedmallBusinessInfoMapper.selectByPrimaryKey(siet.getShopId());
        if (agedmallBusinessInfo == null) {
            return ResponseUtil.fail(700, "店铺不存在");
        }
        AgedmallBusinessInfoExample businessInfoExample = new AgedmallBusinessInfoExample();
        businessInfoExample.or().andBusiNameEqualTo(siet.getShopName()).andDeletedEqualTo(false);
        AgedmallBusinessInfo isUseNameBusiness = agedmallBusinessInfoMapper.selectOneByExample(businessInfoExample);
        if (ObjectUtil.isNotNull(isUseNameBusiness) && !agedmallBusinessInfo.getBusiName().equals(siet.getShopName())) {
            return ResponseUtil.fail(612, "名称重复");
        }
        if (ObjectUtil.isNotNull(siet.getShopDetailMessage())) {
            agedmallBusinessInfo.setProvinceId(siet.getShopDetailMessage().getProvinceId());
            agedmallBusinessInfo.setProvince(siet.getShopDetailMessage().getProvince());
            agedmallBusinessInfo.setCityId(siet.getShopDetailMessage().getCityId());
            agedmallBusinessInfo.setCity(siet.getShopDetailMessage().getCity());
            agedmallBusinessInfo.setVillageId(siet.getShopDetailMessage().getAreaId());
            agedmallBusinessInfo.setVillage(siet.getShopDetailMessage().getArea());
            agedmallBusinessInfo.setAddress(siet.getShopDetailMessage().getDetails());
        }
        agedmallBusinessInfo.setBusiName(siet.getShopName());
        agedmallBusinessInfo.setConcat(siet.getAdministrators());
        agedmallBusinessInfo.setCompanyName(siet.getCompanyName());
        agedmallBusinessInfoMapper.updateByPrimaryKeySelective(agedmallBusinessInfo);
        return ResponseUtil.ok();
    }


    public Object shopInformationShopSetting(ShopInformationShopSettingVo siss) {
        AgedmallBusinessInfo agedmallBusinessInfo = agedmallBusinessInfoMapper.selectByPrimaryKey(siss.getShopId());
        agedmallBusinessInfo.setFreightCalculationType(siss.getFreightCalculation());
        agedmallBusinessInfo.setFreeFreightCalculationType(siss.getFreeShipping());
        agedmallBusinessInfoMapper.updateByPrimaryKeySelective(agedmallBusinessInfo);
        return ResponseUtil.ok();
    }


    public Object getStoreAndCloud(Integer shopId) {
        List<StoreAndCloudBackDto> storeAndCloudBackDtoList = new ArrayList<>();
        AgedmallStoreExample storeExample = new AgedmallStoreExample();
        storeExample.or().andBusiIdEqualTo(shopId).andDeletedEqualTo((byte) 0);
        List<AgedmallStore> agedmallStores = agedmallStoreMapper.selectByExample(storeExample);
        AgedmallCloudHouseExample cloudHouseExample = new AgedmallCloudHouseExample();
        cloudHouseExample.or().andBusIdEqualTo(shopId).andDeletedEqualTo(false);
        List<AgedmallCloudHouse> agedmallCloudHouses = agedmallCloudHouseMapper.selectByExample(cloudHouseExample);
        for (int i = 0; i < agedmallStores.size(); i++) {
            StoreAndCloudBackDto storeAndCloudBackDto = new StoreAndCloudBackDto();
            storeAndCloudBackDto.setId(agedmallStores.get(i).getId().intValue());
            storeAndCloudBackDto.setType(0);
            storeAndCloudBackDto.setName(agedmallStores.get(i).getStoreName());
            storeAndCloudBackDtoList.add(storeAndCloudBackDto);
        }
        for (int i = 0; i < agedmallCloudHouses.size(); i++) {
            StoreAndCloudBackDto storeAndCloudBackDto = new StoreAndCloudBackDto();
            storeAndCloudBackDto.setId(agedmallCloudHouses.get(i).getId().intValue());
            storeAndCloudBackDto.setType(1);
            storeAndCloudBackDto.setName(agedmallCloudHouses.get(i).getName());
            storeAndCloudBackDtoList.add(storeAndCloudBackDto);
        }
        return ResponseUtil.ok(storeAndCloudBackDtoList);
    }

    public Object playerOpt(PlayerAddVo playerAddVo) {
        if (playerAddVo.getOpt().equals("add")) {
            return playerAdd(playerAddVo);
        } else if (playerAddVo.getOpt().equals("edit")) {
            return playerEdit(playerAddVo);
        } else if (playerAddVo.getOpt().equals("unbind")) {
            return playerRemoveBinding(playerAddVo);
        } else {
            return ResponseUtil.fail(644, "操作类型错误");
        }
    }

    public Object playerAdd(PlayerAddVo playerAddVo) {
        AgedmallAnnouncerBaseInfoExample baseInfoExample = new AgedmallAnnouncerBaseInfoExample();
        baseInfoExample.or().andAnnoNumEqualTo(playerAddVo.getPlayerId());
        List<AgedmallAnnouncerBaseInfo> agedmallAnnouncerBaseInfos = agedmallAnnouncerBaseInfoMapper.selectByExample(baseInfoExample);
        if (agedmallAnnouncerBaseInfos.size() <= 0) {
            return ResponseUtil.fail(602, "播报机编号不存在");
        }

        AgedmallAnnouncerBaseInfo agedmallAnnouncerBaseInfo = agedmallAnnouncerBaseInfos.get(0);
        if (agedmallAnnouncerBaseInfos.size() > 0 && agedmallAnnouncerBaseInfo.getStoreId() != null) {
            return ResponseUtil.fail(603, "当前播报机已被绑定");
        } else {
            agedmallAnnouncerBaseInfo.setStoreId(playerAddVo.getStoreId());
            agedmallAnnouncerBaseInfo.setType(playerAddVo.getType());
            agedmallAnnouncerBaseInfo.setVersionId(playerAddVo.getEditionId());
        }
        agedmallAnnouncerBaseInfo.setBusId(playerAddVo.getShopId());
        agedmallAnnouncerBaseInfo.setStat(1);
        agedmallAnnouncerBaseInfo.setBindingTime(LocalDateTime.now());
        agedmallAnnouncerBaseInfoMapper.updateByPrimaryKey(agedmallAnnouncerBaseInfo);
        return ResponseUtil.ok();
    }


    public Object playerEdit(PlayerAddVo playerAddVo) {
        AgedmallAnnouncerBaseInfoExample baseInfoExample = new AgedmallAnnouncerBaseInfoExample();
        baseInfoExample.or().andAnnoNumEqualTo(playerAddVo.getPlayerId());
        List<AgedmallAnnouncerBaseInfo> agedmallAnnouncerBaseInfos = agedmallAnnouncerBaseInfoMapper.selectByExample(baseInfoExample);
        if (agedmallAnnouncerBaseInfos.size() <= 0) {
            return ResponseUtil.fail(602, "播报机编号不存在");
        }

        AgedmallAnnouncerBaseInfo agedmallAnnouncerBaseInfo = agedmallAnnouncerBaseInfos.get(0);
        if (agedmallAnnouncerBaseInfos.size() > 0 && agedmallAnnouncerBaseInfos.get(0).getStoreId() != null && playerAddVo.getStoreId() != null
                && !agedmallAnnouncerBaseInfos.get(0).getStoreId().equals(playerAddVo.getStoreId())) {
            return ResponseUtil.fail(603, "当前播报机已被绑定");
        } else {
            agedmallAnnouncerBaseInfo.setStoreId(playerAddVo.getStoreId());
            agedmallAnnouncerBaseInfo.setType(playerAddVo.getType());
            agedmallAnnouncerBaseInfo.setVersionId(playerAddVo.getEditionId());
        }
        agedmallAnnouncerBaseInfo.setBusId(playerAddVo.getShopId());
        agedmallAnnouncerBaseInfo.setStat(1);
        agedmallAnnouncerBaseInfoMapper.updateByPrimaryKey(agedmallAnnouncerBaseInfo);
        return ResponseUtil.ok();
    }

    public Object playerRemoveBinding(PlayerAddVo playerAddVo) {
        AgedmallAnnouncerBaseInfoExample baseInfoExample = new AgedmallAnnouncerBaseInfoExample();
        baseInfoExample.or().andAnnoNumEqualTo(playerAddVo.getPlayerId());
        List<AgedmallAnnouncerBaseInfo> agedmallAnnouncerBaseInfos = agedmallAnnouncerBaseInfoMapper.selectByExample(baseInfoExample);
        if (agedmallAnnouncerBaseInfos.size() <= 0) {
            return ResponseUtil.fail(602, "播报机编号不存在");
        }
        AgedmallAnnouncerBaseInfo agedmallAnnouncerBaseInfo = agedmallAnnouncerBaseInfos.get(0);
        agedmallAnnouncerBaseInfo.setStoreId(null);
        agedmallAnnouncerBaseInfo.setType(null);
        agedmallAnnouncerBaseInfo.setVersion(null);
        agedmallAnnouncerBaseInfo.setVersionId(null);
        agedmallAnnouncerBaseInfo.setBusId(playerAddVo.getShopId());
        agedmallAnnouncerBaseInfoMapper.updateByPrimaryKey(agedmallAnnouncerBaseInfo);
        return ResponseUtil.ok();
    }


    public Integer changeAnnoState(String stateName) {
        switch (stateName) {
            case "online":
                return 1;
            case "offline":
                return 0;
            default:
                return null;
        }

    }

    public String reverAnnoState(Integer state) {
        switch (state) {
            case 1:
                return "online";
            case 0:
                return "offline";
            default:
                return null;
        }
    }

    public Object playerManagementList(PlayerManagementListVo playerManagementListVo) {
        if (playerManagementListVo.getTime() == null) {
            playerManagementListVo.setTime(new AnnoTime());
        }
        if (playerManagementListVo.getAddress() == null) {
            playerManagementListVo.setAddress(new AnnoAddress());
        }
        Page page = PageHelper.startPage(playerManagementListVo.getPage(), playerManagementListVo.getLimit());
        List<StoreAnnoListDto> storeAnnoListDtos = agedmallShopMapper.selectStoreAnnoList(playerManagementListVo.getShopId(),
                playerManagementListVo.getStoreId(), playerManagementListVo.getType()
                , playerManagementListVo.getTime().getStartTime(), playerManagementListVo.getTime().getEndTime(),
                playerManagementListVo.getAddress().getProvince(), playerManagementListVo.getAddress().getCity(),
                playerManagementListVo.getAddress().getArea(), playerManagementListVo.getState() == null ? null : changeAnnoState(playerManagementListVo.getState()),
                playerManagementListVo.getNumber());
        for (int i = 0; i < storeAnnoListDtos.size(); i++) {
            storeAnnoListDtos.get(i).setState(reverAnnoState(storeAnnoListDtos.get(i).getStat()));
        }
        Map<String, Object> map = new HashMap<>();
        map.put("total", page.getTotal());
        map.put("data", storeAnnoListDtos);
        return ResponseUtil.ok(map);
    }


    public Object playerManagementEditionList(Integer type) {
        AgedmallVersionExample versionExample = new AgedmallVersionExample();
        versionExample.or().andTypeEqualTo(type).andVersionTypeEqualTo(0);
        List<AgedmallVersion> agedmallVersions = agedmallVersionMapper.selectByExample(versionExample);
        return ResponseUtil.ok(agedmallVersions);
    }


    public Object playerDetail(PlayDetailVo playDetailVo) {
        if (playDetailVo.getTime() == null) {
            playDetailVo.setTime(new AnnoTime());
        }
        Page page = PageHelper.startPage(playDetailVo.getPage(), playDetailVo.getLimit());
        List<AnnoDetailBackDto> annoDetailList = agedmallShopMapper.getAnnoDetailList(playDetailVo.getNum(), playDetailVo.getStoreId(),
                playDetailVo.getIc(), playDetailVo.getOrderSn(), playDetailVo.getOrderType(),
                playDetailVo.getTime().getStartTime(), playDetailVo.getTime().getEndTime());
        Map<String, Object> map = new HashMap<>();
        map.put("total", page.getTotal());
        map.put("data", annoDetailList);
        return ResponseUtil.ok(map);
    }


    public Object shopInformationAddpay(ShopInformationAddpayVo shopInformationAddpayVo) {
        AgedmallBusiFinancial agedmallBusiFinancial;
        if (shopInformationAddpayVo.getId() != null) {
            agedmallBusiFinancial = agedmallBusiFinancialMapper.selectByPrimaryKeySelective(shopInformationAddpayVo.getId());
        } else {
            agedmallBusiFinancial = new AgedmallBusiFinancial();
        }
        agedmallBusiFinancial.setType(shopInformationAddpayVo.getPayType());
        agedmallBusiFinancial.setBusId(shopInformationAddpayVo.getShopId());
        if (shopInformationAddpayVo.getPayType() == 0) {
            agedmallBusiFinancial.setAccountCard(shopInformationAddpayVo.getAccount());
            agedmallBusiFinancial.setAccountName(shopInformationAddpayVo.getRealName());
        } else if (shopInformationAddpayVo.getPayType() == 1) {
            agedmallBusiFinancial.setAccountCard(shopInformationAddpayVo.getAccount());
            agedmallBusiFinancial.setAccountName(shopInformationAddpayVo.getRealName());
        } else if (shopInformationAddpayVo.getPayType() == 2) {
            agedmallBusiFinancial.setAccountCard(shopInformationAddpayVo.getBankCard());
            agedmallBusiFinancial.setAccountName(shopInformationAddpayVo.getAccountName());
            agedmallBusiFinancial.setBankName(shopInformationAddpayVo.getBankName());
            agedmallBusiFinancial.setOpeningBank(shopInformationAddpayVo.getBankAccountName());
        } else {
            return ResponseUtil.fail(640, "账号类型不存在");
        }
        if (shopInformationAddpayVo.getId() != null) {
            agedmallBusiFinancialMapper.updateByPrimaryKeySelective(agedmallBusiFinancial);
        } else {
            agedmallBusiFinancial.setAddTime(LocalDateTime.now());
            agedmallBusiFinancialMapper.insertSelective(agedmallBusiFinancial);
        }
        return ResponseUtil.ok();
    }


    public Object shopInformationAccountBink(Integer shopId) {
        AgedmallBusiFinancialExample financialExample = new AgedmallBusiFinancialExample();
        financialExample.or().andBusIdEqualTo(shopId).andDeletedEqualTo(false);
        List<AgedmallBusiFinancial> agedmallBusiFinancials = agedmallBusiFinancialMapper.selectByExample(financialExample);
        return ResponseUtil.ok(agedmallBusiFinancials);
    }

    public Object shopInformationDelFinance(Integer id) {
        agedmallBusiFinancialMapper.logicalDeleteByPrimaryKey(id);
        return ResponseUtil.ok();
    }


    public Object storePositionList(StorePositionId storePositionId) {
        AgedmallStorePositionExample storePositionExample = new AgedmallStorePositionExample();
        storePositionExample.or().andStoreIdEqualTo(storePositionId.getStoreId());
        List<AgedmallStorePosition> agedmallStorePositions = agedmallStorePositionMapper.selectByExample(storePositionExample);
        return ResponseUtil.ok(agedmallStorePositions);
    }

    public void saveGoodsAttribute(Long hospitalId, List<HospitalSendGoodsVo> goodsVoList) {
        List<AgedmallHospitalSendGoodsAttribute> goodsAttributeList = new ArrayList<>();
        for (int i = 0; i < goodsVoList.size(); i++) {
            AgedmallHospitalSendGoodsAttribute goodsAttribute = new AgedmallHospitalSendGoodsAttribute();
            goodsAttribute.setGoodsId(goodsVoList.get(i).getGoodsId().longValue());
            goodsAttribute.setHospitalSendId(hospitalId);
            goodsAttribute.setHospitalShow(goodsVoList.get(i).getHospitalShow());
            goodsAttribute.setCarerShow(goodsVoList.get(i).getCarerShow());
            goodsAttribute.setHospitalSendType(goodsVoList.get(i).getHospitalSend());
            goodsAttribute.setCarerSendType(goodsVoList.get(i).getCarerSend());
            goodsAttributeList.add(goodsAttribute);
        }
        agedmallShopMapper.insertGoodsAttributeList(goodsAttributeList);

    }


    public void saveStoreAttribute(Long hospitalId, List<HospitalSendStoreVo> sendStoreVoList) {
        List<AgedmallHospitalSendStoreAttribute> storeAttributeList = new ArrayList<>();
        for (int i = 0; i < sendStoreVoList.size(); i++) {
            AgedmallHospitalSendStoreAttribute storeAttribute = new AgedmallHospitalSendStoreAttribute();
            storeAttribute.setStoreId(sendStoreVoList.get(i).getStoreId().longValue());
            storeAttribute.setHospitalSendId(hospitalId);
            storeAttribute.setSendType(sendStoreVoList.get(i).getSendType());
            storeAttributeList.add(storeAttribute);
        }
        agedmallShopMapper.insertStoreAttributeList(storeAttributeList);

    }

    public void saveSelfLocationAttribute(Long hospitalId, List<HospitalSelfLocationVo> hospitalSelfLocationVoList) {
        List<AgedmallHospitalSendSelfLocation> locationList = new ArrayList<>();
        if (hospitalSelfLocationVoList != null) {
            for (int i = 0; i < hospitalSelfLocationVoList.size(); i++) {
                AgedmallHospitalSendSelfLocation hospitalSendSelfLocation = HospitalSelfLocationVo.toHospitalSelfLocation(hospitalSelfLocationVoList.get(i), hospitalId);
                //如果有具体rfid，保存具体rfid列表
                if (hospitalSelfLocationVoList.get(i).getHospitalSelfLocationEquList() != null) {
                    agedmallHospitalSendSelfLocationMapper.insertSelective(hospitalSendSelfLocation);
                    saveSelfLocationGoodsEquAttribute(hospitalSendSelfLocation.getId(), hospitalSelfLocationVoList.get(i).getHospitalSelfLocationEquList());
                } else {
                    locationList.add(hospitalSendSelfLocation);
                }

            }
            if (locationList.size() > 0) {
                agedmallShopMapper.insertSelfLocationAttributeList(locationList);
            }

        }
    }

    public void modifySelfLocationAttribute(Long hospitalId, List<HospitalSelfLocationVo> hospitalSelfLocationVoList) {
        List<AgedmallHospitalSendSelfLocation> modifyLocationList = new ArrayList<>();
        List<AgedmallHospitalSendSelfLocation> addLocationList = new ArrayList<>();
        List<AgedmallHospitalSendSelfLocation> deleteLocationList = new ArrayList<>();

        List<Long> oldSelfLocation = new ArrayList<>();
        List<Long> nowSelfLocation = new ArrayList<>();
        AgedmallHospitalSendSelfLocationExample locationExample = new AgedmallHospitalSendSelfLocationExample();
        locationExample.createCriteria().andDeletedEqualTo(false).andHospitalIdEqualTo(hospitalId);
        List<AgedmallHospitalSendSelfLocation> locationList = agedmallHospitalSendSelfLocationMapper.selectByExample(locationExample);
        locationList.forEach(location -> oldSelfLocation.add(location.getId()));

        if (hospitalSelfLocationVoList != null) {
            for (int i = 0; i < hospitalSelfLocationVoList.size(); i++) {
                AgedmallHospitalSendSelfLocation hospitalSendSelfLocation = HospitalSelfLocationVo.toHospitalSelfLocation(hospitalSelfLocationVoList.get(i), hospitalId);
                //如果有具体rfid，保存具体rfid列表
                if (hospitalSelfLocationVoList.get(i).getHospitalSelfLocationEquList() != null) {
                    modifySelfLocationGoodsEquAttribute(hospitalSendSelfLocation.getId(), hospitalSelfLocationVoList.get(i).getHospitalSelfLocationEquList());
                }
                if (hospitalSendSelfLocation.getId() == null) {
                    addLocationList.add(hospitalSendSelfLocation);
                } else {
                    modifyLocationList.add(hospitalSendSelfLocation);
                }
            }
            if (modifyLocationList.size() > 0) {
                agedmallShopMapper.updateSelfLocationAttributeList(modifyLocationList);
                modifyLocationList.forEach(location -> nowSelfLocation.add(location.getId()));
            }
            if (addLocationList.size() > 0) {
                agedmallShopMapper.insertSelfLocationAttributeList(addLocationList);
            }
            //获取原本和现在更新的差异，差异的删除
            if (oldSelfLocation.size() > 0) {
                List<Long> diff = getDiff(oldSelfLocation, nowSelfLocation);
                if (diff.size() > 0) {
                    deleteSelfLocation(diff);
                }
            }

        }
    }


    private static List<Long> getDiff(List<Long> oldList, List<Long> newList) {
        List<Long> diff = new ArrayList<Long>();
        for (int i = 0; i < oldList.size(); i++) {
            if (!newList.contains(oldList.get(i))) {
                diff.add(oldList.get(i));
            }
        }
        return diff;
    }


    public void saveSelfLocationGoodsEquAttribute(Long selfLocationId, List<HospitalSelfLocationEquVo> equVoList) {
        List<AgedmallGoodsEqu> equList = new ArrayList<>();
        List<AgedmallHospitalSendSelfLocationEqu> equRelationList = new ArrayList<>();
        for (int i = 0; i < equVoList.size(); i++) {
            String[] rfidList = equVoList.get(i).getEquIdArray().split(",");
            for (int j = 0; j < rfidList.length; j++) {
                Long rfid = Long.parseLong(rfidList[j]);
                AgedmallHospitalSendSelfLocationEqu locationEqu = HospitalSelfLocationEquVo.toequRelation(selfLocationId, rfid);
                AgedmallGoodsEqu goodsEqu = HospitalSelfLocationEquVo.toGoodsEqu(equVoList.get(i), rfid);
                equRelationList.add(locationEqu);
                equList.add(goodsEqu);
            }
        }
        if (equList.size() > 0) {

            agedmallShopMapper.insertHospitalGoodsEquList(equList);
        }
        if (equRelationList.size() > 0) {
            agedmallShopMapper.insertHospitalGoodsEquRelationList(equRelationList);
        }
    }


    public void modifySelfLocationGoodsEquAttribute(Long selfLocationId, List<HospitalSelfLocationEquVo> equVoList) {
        List<Long> equIdList = new ArrayList<>();
        ;
        List<Long> relationList = new ArrayList<>();
        for (int i = 0; i < equVoList.size(); i++) {
            String[] rfidList = equVoList.get(i).getEquIdArray().split(",");
            for (int j = 0; j < rfidList.length; j++) {
                Long rfid = Long.parseLong(rfidList[j]);
                equIdList.add(rfid);
            }
        }
        AgedmallGoodsEquExample goodsEquExample = new AgedmallGoodsEquExample();
        goodsEquExample.createCriteria().andDeletedEqualTo((byte) 0).andTypeEqualTo(2).andEquIdIn(equIdList);
        agedmallGoodsEquMapper.logicalDeleteByExample(goodsEquExample);

        AgedmallHospitalSendSelfLocationEquExample locationEquExample = new AgedmallHospitalSendSelfLocationEquExample();
        locationEquExample.createCriteria().andHospitalSelfLocationIdEqualTo(selfLocationId);
        agedmallHospitalSendSelfLocationEquMapper.logicalDeleteByExample(locationEquExample);

        saveSelfLocationGoodsEquAttribute(selfLocationId, equVoList);

    }


    public void modifyGoodsAttribute(Long hospitalId, List<HospitalSendGoodsVo> goodsVoList) {
        AgedmallHospitalSendGoodsAttributeExample goodsAttributeExample = new AgedmallHospitalSendGoodsAttributeExample();
        goodsAttributeExample.createCriteria().andHospitalSendIdEqualTo(hospitalId);
        agedmallHospitalSendGoodsAttributeMapper.deleteByExample(goodsAttributeExample);
        saveGoodsAttribute(hospitalId, goodsVoList);
    }

    public void modifyStoreAttribute(Long hospitalId, List<HospitalSendStoreVo> sendStoreVoList) {
        AgedmallHospitalSendStoreAttributeExample storeAttributeExample = new AgedmallHospitalSendStoreAttributeExample();
        storeAttributeExample.createCriteria().andHospitalSendIdEqualTo(hospitalId);
        agedmallHospitalSendStoreAttributeMapper.deleteByExample(storeAttributeExample);
        saveStoreAttribute(hospitalId, sendStoreVoList);
    }


    public AgedmallHospitalSend addOneHospitalSend(HospitalSendVo hospitalSendVo, HospitalSendDeliveryTypeVo deliveryTypeVo) {
        AgedmallHospitalSend agedmallHospitalSend = new AgedmallHospitalSend();
        AgedmallHospitalSendExample sendExample = new AgedmallHospitalSendExample();
        sendExample.or().andDeletedEqualTo(false).andHospitalNameEqualTo(hospitalSendVo.getHospitalName());
        AgedmallHospitalSend isExistHospital = agedmallHospitalSendMapper.selectOneByExample(sendExample);
        if (ObjectUtil.isNotNull(isExistHospital)) {
            throw new BizException("医院名称已存在");
        }
        agedmallHospitalSend.setHospitalName(hospitalSendVo.getHospitalName());
        agedmallHospitalSend.setProvinceId(hospitalSendVo.getProvinceId());
        agedmallHospitalSend.setCityId(hospitalSendVo.getCityId());
        agedmallHospitalSend.setVillageId(hospitalSendVo.getVillageId());
        agedmallHospitalSend.setProvince(hospitalSendVo.getProvince());
        agedmallHospitalSend.setCity(hospitalSendVo.getCity());
        agedmallHospitalSend.setVillage(hospitalSendVo.getVillage());
        agedmallHospitalSend.setAddressDetail(hospitalSendVo.getAddressDetail());
        agedmallHospitalSend.setStoreIds(hospitalSendVo.getStoreIds());
        agedmallHospitalSend.setGoodsType(hospitalSendVo.getGoodsType());
        List<Integer> goodsIdList = new ArrayList<>();
        hospitalSendVo.getGoodsData().forEach(goods -> goodsIdList.add(goods.getGoodsId()));
        agedmallHospitalSend.setGoodsIds(StringUtils.join(goodsIdList, ","));
        agedmallHospitalSend.setUrgentCost(deliveryTypeVo.getUrgentCost());
        agedmallHospitalSend.setDeliveryTime(deliveryTypeVo.getDeliveryTime());
        agedmallHospitalSend.setBusiId(deliveryTypeVo.getShopId());
        agedmallHospitalSend.setLng(hospitalSendVo.getLng());
        agedmallHospitalSend.setLat(hospitalSendVo.getLat());
        agedmallHospitalSend.setOnlyToHospital(deliveryTypeVo.getOnlyToHospital());
        agedmallHospitalSend.setHourReach(deliveryTypeVo.getHourReach());
        agedmallHospitalSend.setSubscribe(deliveryTypeVo.getSubscribe());
        if (deliveryTypeVo.getSubscribe().equals(1)) {
            agedmallHospitalSend.setSubscribeDay(deliveryTypeVo.getSubscribeDay());
            List<HospitalSendTimePeriodDto> periodDtos = deliveryTypeVo.getTimePeriods();
            int i = 1;
            for (HospitalSendTimePeriodDto periodDto : periodDtos) {
                periodDto.setId(i++);
            }
            agedmallHospitalSend.setTimePeriod(JSON.toJSONString(periodDtos));
        }
        agedmallHospitalSend.setAddTime(LocalDateTime.now());
        agedmallHospitalSendMapper.insertSelective(agedmallHospitalSend);
        saveGoodsAttribute(agedmallHospitalSend.getId().longValue(), hospitalSendVo.getGoodsData());
        saveStoreAttribute(agedmallHospitalSend.getId().longValue(), hospitalSendVo.getStoreData());
        if (hospitalSendVo.getHospitalSelfLocation() != null) {
            //保存自提位置信息
            saveSelfLocationAttribute(agedmallHospitalSend.getId().longValue(), hospitalSendVo.getHospitalSelfLocation());
        }
        return agedmallHospitalSend;
    }

    public void saveHospitalRelation(Integer hospitalId, Integer parentHospitalId) {
        AgedmallHospitalSendRelation sendRelation = new AgedmallHospitalSendRelation();
        sendRelation.setHospitalSendId(hospitalId);
        if (parentHospitalId == null) {
            sendRelation.setHospitalParentId(0);
            sendRelation.setIsMain(1);
        } else {
            sendRelation.setHospitalParentId(parentHospitalId);
            sendRelation.setIsMain(0);
        }
        sendRelation.setAddTime(LocalDateTime.now());
        agedmallHospitalSendRelationMapper.insertSelective(sendRelation);
    }

    /**
     * 新增医院检查自提医院库存 rfid是否已经存在于数据库，如果存在，则报错返回
     */
    public List<Long> insertCheckRfidIsExist(HospitalSendVo hospitalSendVo) {
        List<Long> existRfid = new ArrayList<>();
        List<Long> equList = new ArrayList<>();
        if(hospitalSendVo.getHospitalSelfLocation()!=null){
        for (int i = 0; i < hospitalSendVo.getHospitalSelfLocation().size(); i++) {
            List<HospitalSelfLocationEquVo> equBeanList = hospitalSendVo.getHospitalSelfLocation().get(i).getHospitalSelfLocationEquList();
            if (equBeanList != null) {
                for (int j = 0; j < equBeanList.size(); j++) {
                    String[] equIdArray = equBeanList.get(j).getEquIdArray().split(",");
                    for (int k = 0; k < equIdArray.length; k++) {
                        equList.add(Long.parseLong(equIdArray[k]));
                    }
                }
            }
        }
        }

        if (equList.size() > 0) {
            AgedmallGoodsEquExample goodsEquExample = new AgedmallGoodsEquExample();
            goodsEquExample.createCriteria().andEquIdIn(equList).andDeletedEqualTo((byte) 0).andTypeEqualTo(0);
            AgedmallGoodsEquExample hospitalGoodsEquExample = new AgedmallGoodsEquExample();
            hospitalGoodsEquExample.createCriteria().andEquIdIn(equList).andDeletedEqualTo((byte) 0).andTypeEqualTo(2);
            List<AgedmallGoodsEqu> goodsEquList = agedmallGoodsEquMapper.selectByExample(goodsEquExample);
            List<AgedmallGoodsEqu> hospitalGoodsEquList = agedmallGoodsEquMapper.selectByExample(hospitalGoodsEquExample);
            if (goodsEquList != null && goodsEquList.size() > 0) {
                goodsEquList.forEach(goodsEqu -> existRfid.add(goodsEqu.getEquId()));
            }
            if (hospitalGoodsEquList != null && hospitalGoodsEquList.size() > 0) {
                hospitalGoodsEquList.forEach(goodsEqu -> existRfid.add(goodsEqu.getEquId()));
            }
        }
        return existRfid;
    }

    /**
     * 编辑医院检查自提医院库存 rfid是否已经存在于数据库，如果存在，则报错返回
     */
    public List<Long> modifyCheckRfidIsExist(HospitalSendVo hospitalSendVo) {
        //传的rfid在医院库存中原本不存在
        List<Long> notExistHospitalRfid = new ArrayList<>();
        //
        List<Long> existRfid = new ArrayList<>();
        //已存在并且不是医院库存
        List<Long> errorRfid = new ArrayList<>();

        List<Long> locationRfid = new ArrayList<>();
        if (hospitalSendVo.getHospitalSelfLocation() != null) {

            for (int i = 0; i < hospitalSendVo.getHospitalSelfLocation().size(); i++) {
                List<HospitalSelfLocationEquVo> equBeanList = hospitalSendVo.getHospitalSelfLocation().get(i).getHospitalSelfLocationEquList();
                if (equBeanList != null) {
                    for (int j = 0; j < equBeanList.size(); j++) {
                        String[] equIdArray = equBeanList.get(j).getEquIdArray().split(",");
                        for (int k = 0; k < equIdArray.length; k++) {
                            locationRfid.add(Long.parseLong(equIdArray[k]));
                        }
                    }
                }
            }
            if (locationRfid.size() > 0) {

                AgedmallGoodsEquExample goodsEquExample = new AgedmallGoodsEquExample();
                goodsEquExample.createCriteria().andEquIdIn(locationRfid).andDeletedEqualTo((byte) 0).andTypeEqualTo(0);
                List<AgedmallGoodsEqu> goodsEquList = agedmallGoodsEquMapper.selectByExample(goodsEquExample);

                if (goodsEquList != null && goodsEquList.size() > 0) {
                    goodsEquList.forEach(goodsEqu -> errorRfid.add(goodsEqu.getEquId()));
                    return errorRfid;
                }
                //去重 如果有重复的，返回-1
                List<Long> collect = locationRfid.stream().distinct().collect(Collectors.toList());
                if (collect.size() != locationRfid.size()) {
                    errorRfid.add(-1L);
                }

            }

        }
        return errorRfid;
    }


    public Object addHospitalSend(ModifyHospitalVo modifyHospitalVo) {
        //新增和修改之前如果equId已经存在，则直接报错返回
        List<Long> existRfid = new ArrayList<>();
        existRfid.addAll(insertCheckRfidIsExist(modifyHospitalVo.getMainHospital()));
        for (int i = 0; i < modifyHospitalVo.getOtherHospital().size(); i++) {
            existRfid.addAll(insertCheckRfidIsExist(modifyHospitalVo.getOtherHospital().get(i)));
        }
        if (existRfid.size() > 0) {
            return ResponseUtil.fail(500, "编号(" + StringUtils.join(existRfid, ",") + ")已存在");
        }

        AgedmallHospitalSend mainHospital = addOneHospitalSend(modifyHospitalVo.getMainHospital(), modifyHospitalVo.getDeliveryType());
        saveHospitalRelation(mainHospital.getId(), null);
        if (!modifyHospitalVo.getOtherHospital().isEmpty()) {
            for (int i = 0; i < modifyHospitalVo.getOtherHospital().size(); i++) {
                AgedmallHospitalSend otherHospital = addOneHospitalSend(modifyHospitalVo.getOtherHospital().get(i), modifyHospitalVo.getDeliveryType());
                saveHospitalRelation(otherHospital.getId(), mainHospital.getId());
            }
        }
        return ResponseUtil.ok();
    }


    public AgedmallHospitalSend modifyOneHospitalSend(HospitalSendVo hospitalSendVo, HospitalSendDeliveryTypeVo deliveryTypeVo) {
        AgedmallHospitalSend agedmallHospitalSend = agedmallHospitalSendMapper.selectByPrimaryKey(hospitalSendVo.getId());
        AgedmallHospitalSendExample sendExample = new AgedmallHospitalSendExample();
        sendExample.or().andDeletedEqualTo(false).andHospitalNameEqualTo(hospitalSendVo.getHospitalName());
        AgedmallHospitalSend isExistHospital = agedmallHospitalSendMapper.selectOneByExample(sendExample);
        if (ObjectUtil.isNotNull(isExistHospital) && !hospitalSendVo.getHospitalName().equals(agedmallHospitalSend.getHospitalName())) {
            throw new BizException("医院名称已存在");
        }
        agedmallHospitalSend.setHospitalName(hospitalSendVo.getHospitalName());
        agedmallHospitalSend.setProvinceId(hospitalSendVo.getProvinceId());
        agedmallHospitalSend.setCityId(hospitalSendVo.getCityId());
        agedmallHospitalSend.setVillageId(hospitalSendVo.getVillageId());
        agedmallHospitalSend.setProvince(hospitalSendVo.getProvince());
        agedmallHospitalSend.setCity(hospitalSendVo.getCity());
        agedmallHospitalSend.setVillage(hospitalSendVo.getVillage());
        agedmallHospitalSend.setAddressDetail(hospitalSendVo.getAddressDetail());
        agedmallHospitalSend.setStoreIds(hospitalSendVo.getStoreIds());
        agedmallHospitalSend.setGoodsType(hospitalSendVo.getGoodsType());
        List<Integer> goodsIdList = new ArrayList<>();
        hospitalSendVo.getGoodsData().forEach(goods -> goodsIdList.add(goods.getGoodsId()));
        agedmallHospitalSend.setGoodsIds(StringUtils.join(goodsIdList, ","));
        agedmallHospitalSend.setUrgentCost(deliveryTypeVo.getUrgentCost());
        agedmallHospitalSend.setDeliveryTime(deliveryTypeVo.getDeliveryTime());
        agedmallHospitalSend.setBusiId(deliveryTypeVo.getShopId());
        agedmallHospitalSend.setLng(hospitalSendVo.getLng());
        agedmallHospitalSend.setLat(hospitalSendVo.getLat());
        agedmallHospitalSend.setOnlyToHospital(deliveryTypeVo.getOnlyToHospital());
        agedmallHospitalSend.setHourReach(deliveryTypeVo.getHourReach());
        agedmallHospitalSend.setSubscribe(deliveryTypeVo.getSubscribe());
        if (deliveryTypeVo.getSubscribe().equals(1)) {
            agedmallHospitalSend.setSubscribeDay(deliveryTypeVo.getSubscribeDay());
            List<HospitalSendTimePeriodDto> periodDtos = deliveryTypeVo.getTimePeriods();
            int i = 1;
            for (HospitalSendTimePeriodDto periodDto : periodDtos) {
                periodDto.setId(i++);
            }
            agedmallHospitalSend.setTimePeriod(JSON.toJSONString(periodDtos));
        }
        agedmallHospitalSend.setAddTime(LocalDateTime.now());
        agedmallHospitalSendMapper.updateByPrimaryKeySelective(agedmallHospitalSend);
        modifyGoodsAttribute(agedmallHospitalSend.getId().longValue(), hospitalSendVo.getGoodsData());
        modifyStoreAttribute(agedmallHospitalSend.getId().longValue(), hospitalSendVo.getStoreData());

        modifySelfLocationAttribute(agedmallHospitalSend.getId().longValue(), hospitalSendVo.getHospitalSelfLocation());
        return agedmallHospitalSend;
    }


    public Object modifyHospitalSend(ModifyHospitalVo modifyHospitalVo) {
        //首先判断rfid modifyCheckRfidIsExist
        List<Long> existRfid = new ArrayList<>();
        existRfid.addAll(modifyCheckRfidIsExist(modifyHospitalVo.getMainHospital()));
        for (int i = 0; i < modifyHospitalVo.getOtherHospital().size(); i++) {
            existRfid.addAll(modifyCheckRfidIsExist(modifyHospitalVo.getOtherHospital().get(i)));
        }
        if (existRfid.size() > 0) {
            return ResponseUtil.fail(500, "编号(" + StringUtils.join(existRfid, ",") + ")已存在");
        }

        AgedmallHospitalSend mainHospital = modifyOneHospitalSend(modifyHospitalVo.getMainHospital(), modifyHospitalVo.getDeliveryType());
        AgedmallHospitalSendRelationExample relationExample = new AgedmallHospitalSendRelationExample();
        relationExample.createCriteria().andHospitalParentIdEqualTo(mainHospital.getId());
        List<AgedmallHospitalSendRelation> agedmallHospitalSendRelations = agedmallHospitalSendRelationMapper.selectByExample(relationExample);
        List<Integer> relationIdList = new ArrayList<>();
        agedmallHospitalSendRelations.forEach(relation -> relationIdList.add(relation.getHospitalSendId()));
        //如果原来关联了分院，现在没有分院
        if (relationIdList.size() > 0 && modifyHospitalVo.getOtherHospital().size() == 0) {
            AgedmallHospitalSendExample sendExample = new AgedmallHospitalSendExample();
            sendExample.createCriteria().andIdIn(relationIdList);
            agedmallHospitalSendMapper.logicalDeleteByExample(sendExample);
            agedmallHospitalSendRelationMapper.deleteByExample(relationExample);
        }
        //如果原来没有分院，现在有了
        else if (relationIdList.size() == 0 && modifyHospitalVo.getOtherHospital().size() > 0) {
            for (int i = 0; i < modifyHospitalVo.getOtherHospital().size(); i++) {
                AgedmallHospitalSend otherHospital = addOneHospitalSend(modifyHospitalVo.getOtherHospital().get(i), modifyHospitalVo.getDeliveryType());
                saveHospitalRelation(otherHospital.getId(), mainHospital.getId());
            }
        } else {
            for (int i = 0; i < modifyHospitalVo.getOtherHospital().size(); i++) {
                //新增
                if (modifyHospitalVo.getOtherHospital().get(i).getId() == null) {
                    AgedmallHospitalSend otherHospital = addOneHospitalSend(modifyHospitalVo.getOtherHospital().get(i), modifyHospitalVo.getDeliveryType());
                    saveHospitalRelation(otherHospital.getId(), mainHospital.getId());
                }
                //包含为修改
                else if (relationIdList.contains(modifyHospitalVo.getOtherHospital().get(i).getId())) {
                    modifyOneHospitalSend(modifyHospitalVo.getOtherHospital().get(i), modifyHospitalVo.getDeliveryType());
                }
                //不包含为删除
                else {
                    agedmallHospitalSendMapper.logicalDeleteByPrimaryKey(modifyHospitalVo.getOtherHospital().get(i).getId());
                    AgedmallHospitalSendSelfLocationExample locationExample = new AgedmallHospitalSendSelfLocationExample();
                    locationExample.createCriteria().andHospitalIdEqualTo(modifyHospitalVo.getOtherHospital().get(i).getId().longValue()).andDeletedEqualTo(false);
                    List<AgedmallHospitalSendSelfLocation> selfLocationList = agedmallHospitalSendSelfLocationMapper.selectByExample(locationExample);
                    agedmallHospitalSendSelfLocationMapper.logicalDeleteByExample(locationExample);
                    List<Long> selfLocationIdList = new ArrayList<>();
                    selfLocationList.forEach(selfLocation -> selfLocationIdList.add(selfLocation.getId()));
                    if (selfLocationIdList.size() > 0) {
                        deleteSelfLocation(selfLocationIdList);

                    }

                }
            }
        }
        return ResponseUtil.ok();
    }

    /**
     * 删除自提点
     *
     * @param locationList
     */
    public void deleteSelfLocation(List<Long> locationList) {
        if (locationList.size() > 0) {
            AgedmallHospitalSendSelfLocationExample sendSelfLocationExample=new AgedmallHospitalSendSelfLocationExample();
            sendSelfLocationExample.createCriteria().andIdIn(locationList);
            agedmallHospitalSendSelfLocationMapper.logicalDeleteByExample(sendSelfLocationExample);
            AgedmallHospitalSendSelfLocationEquExample locationEquExample = new AgedmallHospitalSendSelfLocationEquExample();
            locationEquExample.createCriteria().andHospitalSelfLocationIdIn(locationList);
            List<AgedmallHospitalSendSelfLocationEqu> equList = agedmallHospitalSendSelfLocationEquMapper.selectByExample(locationEquExample);
            agedmallHospitalSendSelfLocationEquMapper.logicalDeleteByExample(locationEquExample);
            List<Long> goodsEquIdList = new ArrayList<>();
            equList.forEach(equ -> goodsEquIdList.add(equ.getEquId()));
            if (goodsEquIdList.size() > 0) {
                AgedmallGoodsEquExample goodsEquExample = new AgedmallGoodsEquExample();
                goodsEquExample.createCriteria().andTypeEqualTo(2).andEquIdIn(goodsEquIdList);
                agedmallGoodsEquMapper.logicalDeleteByExample(goodsEquExample);
            }
        }
    }


    public Object delHospitalSend(List<Integer> id) {
        for (int i = 0; i < id.size(); i++) {
            //删除主院
            agedmallHospitalSendMapper.logicalDeleteByPrimaryKey(id.get(i));
            //删除主院的商品
            AgedmallHospitalSendGoodsAttributeExample mainGoodsAttributeExample = new AgedmallHospitalSendGoodsAttributeExample();
            mainGoodsAttributeExample.createCriteria().andHospitalSendIdEqualTo(id.get(i).longValue());
            agedmallHospitalSendGoodsAttributeMapper.deleteByExample(mainGoodsAttributeExample);
            //删除主院的门店
            AgedmallHospitalSendStoreAttributeExample mainStoreAttributeExample = new AgedmallHospitalSendStoreAttributeExample();
            mainStoreAttributeExample.createCriteria().andHospitalSendIdEqualTo(id.get(i).longValue());
            agedmallHospitalSendStoreAttributeMapper.deleteByExample(mainStoreAttributeExample);

            AgedmallHospitalSendRelationExample relationExample = new AgedmallHospitalSendRelationExample();
            relationExample.createCriteria().andHospitalParentIdEqualTo(id.get(i));
            List<AgedmallHospitalSendRelation> agedmallHospitalSendRelations = agedmallHospitalSendRelationMapper.selectByExample(relationExample);


            //删除主院的自提点
            List<Long> selfLocation = new ArrayList<>();
            AgedmallHospitalSendSelfLocationExample locationExample = new AgedmallHospitalSendSelfLocationExample();
            locationExample.createCriteria().andDeletedEqualTo(false).andHospitalIdEqualTo(id.get(i).longValue());
            List<AgedmallHospitalSendSelfLocation> locationList = agedmallHospitalSendSelfLocationMapper.selectByExample(locationExample);
            locationList.forEach(location -> selfLocation.add(location.getId()));
            deleteSelfLocation(selfLocation);

            //删除分院关联
            agedmallHospitalSendRelationMapper.deleteByExample(relationExample);
            //删除自己的关联
            AgedmallHospitalSendRelationExample selfExample = new AgedmallHospitalSendRelationExample();
            selfExample.createCriteria().andHospitalSendIdEqualTo(id.get(i));
            agedmallHospitalSendRelationMapper.deleteByExample(selfExample);
            //删除分院
            List<Integer> relationIdList = new ArrayList<>();
            List<Long> longRelationIdList = new ArrayList<>();
            agedmallHospitalSendRelations.forEach(relation ->
                    {
                        relationIdList.add(relation.getHospitalSendId());
                        longRelationIdList.add(relation.getHospitalSendId().longValue());
                    }

            );
            if (!relationIdList.isEmpty()) {
                AgedmallHospitalSendExample sendExample = new AgedmallHospitalSendExample();
                sendExample.createCriteria().andIdIn(relationIdList);
                agedmallHospitalSendMapper.logicalDeleteByExample(sendExample);
            }
            if (!longRelationIdList.isEmpty()) {
                //删除分院的商品
                AgedmallHospitalSendGoodsAttributeExample otherGoodsAttributeExample = new AgedmallHospitalSendGoodsAttributeExample();
                otherGoodsAttributeExample.createCriteria().andHospitalSendIdIn(longRelationIdList);
                agedmallHospitalSendGoodsAttributeMapper.deleteByExample(otherGoodsAttributeExample);
                //删除分院的门店
                AgedmallHospitalSendStoreAttributeExample otherStoreAttributeExample = new AgedmallHospitalSendStoreAttributeExample();
                otherStoreAttributeExample.createCriteria().andHospitalSendIdEqualTo(id.get(i).longValue());
                agedmallHospitalSendStoreAttributeMapper.deleteByExample(otherStoreAttributeExample);

                //删除分院的自提点
                List<Long> otherSelfLocation = new ArrayList<>();
                AgedmallHospitalSendSelfLocationExample otherLocationExample = new AgedmallHospitalSendSelfLocationExample();
                locationExample.createCriteria().andDeletedEqualTo(false).andHospitalIdIn(longRelationIdList);
                List<AgedmallHospitalSendSelfLocation> otherLocationList = agedmallHospitalSendSelfLocationMapper.selectByExample(otherLocationExample);
                otherLocationList.forEach(location -> otherSelfLocation.add(location.getId()));
                deleteSelfLocation(otherSelfLocation);

            }
        }

        return ResponseUtil.ok();
    }

    public Object hospitalSendList(HospitalSendListVo hospitalSendListVo) {
        Page page = PageHelper.startPage(hospitalSendListVo.getPage(), hospitalSendListVo.getLimit());
        List<HospitalSendDto> mainHospitalSendList = agedmallShopMapper.getHospitalSendList(hospitalSendListVo.getShopId(), hospitalSendListVo.getProvince(), hospitalSendListVo.getCity(),
                hospitalSendListVo.getVillage(), hospitalSendListVo.getKeySearch());
        List<HospitalSendBackDto> backDtoList = new ArrayList<>();
        for (int i = 0; i < mainHospitalSendList.size(); i++) {
            HospitalSendBackDto sendBackDto = new HospitalSendBackDto();
            sendBackDto.setMainHospital(assembSendData(mainHospitalSendList.get(i)));
            List<HospitalSendDto> otherHospitalSendList = agedmallShopMapper.getOtherHospitalSendList(mainHospitalSendList.get(i).getId());
            sendBackDto.setOtherHospital(assembSendDataList(otherHospitalSendList));
            sendBackDto.setDeliveryType(new HospitalSendDeliveryTypeVo(mainHospitalSendList.get(i)));
            backDtoList.add(sendBackDto);
        }
        Map<String, Object> map = new HashMap<>();
        map.put("total", page.getTotal());
        map.put("data", backDtoList);
        return ResponseUtil.ok(map);
    }


    public HospitalSendDto assembSendData(HospitalSendDto hospitalSendDto) {

        //门店
        List<Long> storeIds = new ArrayList<>();
        String[] storeIdString = hospitalSendDto.getStoreIds().split(",");
        for (String storeId : storeIdString) {
            storeIds.add(Long.parseLong(storeId));
        }
        AgedmallStoreExample storeExample = new AgedmallStoreExample();
        storeExample.or().andIdIn(storeIds);
        List<AgedmallStore> agedmallStores = agedmallStoreMapper.selectByExample(storeExample);
        List<BackendStoreListVo> backendStoreListVos = new ArrayList<>();
        AgedmallHospitalSendStoreAttributeExample storeAttributeExample = new AgedmallHospitalSendStoreAttributeExample();
        storeAttributeExample.createCriteria().andStoreIdIn(storeIds).andHospitalSendIdEqualTo(hospitalSendDto.getId().longValue());
        List<AgedmallHospitalSendStoreAttribute> storeAttributeList = agedmallHospitalSendStoreAttributeMapper.selectByExample(storeAttributeExample);
        for (int i = 0; i < agedmallStores.size(); i++) {
            for (int j = 0; j < storeAttributeList.size(); j++) {
                if (agedmallStores.get(i).getId().equals(storeAttributeList.get(j).getStoreId())) {
                    BackendStoreListVo backendStoreListVo = new BackendStoreListVo(agedmallStores.get(i), storeAttributeList.get(j));
                    backendStoreListVos.add(backendStoreListVo);
                }
            }
        }
        hospitalSendDto.setStoreList(backendStoreListVos);

        //商品
        List<Integer> goodsIdList = new ArrayList<>();
        String[] goodsIdString = hospitalSendDto.getGoodsIds().split(",");
        for (String goodsId : goodsIdString) {
            goodsIdList.add(Integer.parseInt(goodsId));
        }
        if (!goodsIdList.isEmpty()) {
            List<HospitalSendGoodsDto> hospitalGoodsAttribute = agedmallShopMapper.getHospitalGoodsAttribute(goodsIdList, hospitalSendDto.getId().longValue());
            hospitalSendDto.setGoodsList(hospitalGoodsAttribute);
        }

        //自提点
        AgedmallHospitalSendSelfLocationExample locationExample = new AgedmallHospitalSendSelfLocationExample();
        locationExample.createCriteria().andHospitalIdEqualTo(hospitalSendDto.getId().longValue()).andDeletedEqualTo(false);
        List<AgedmallHospitalSendSelfLocation> locationList = agedmallHospitalSendSelfLocationMapper.selectByExample(locationExample);
        List<HospitalSelfLocationVo> selfLocationVoList = HospitalSelfLocationVo.toSelfLocationVo(locationList);
        for (int i = 0; i < selfLocationVoList.size(); i++) {
            if (selfLocationVoList.get(i).getInventoryFlag() == 0) {
                List<HospitalSelfLocationEquVo> equListByHospitalSend = agedmallShopMapper.getEquListByHospitalSend(selfLocationVoList.get(i).getId());
                selfLocationVoList.get(i).setHospitalSelfLocationEquList(equListByHospitalSend);
            }
        }
        hospitalSendDto.setLocationVoList(selfLocationVoList);
        return hospitalSendDto;
    }

    public List<HospitalSendDto> assembSendDataList(List<HospitalSendDto> sendDtoList) {
        List<HospitalSendDto> backDto = new ArrayList<>();
        for (int i = 0; i < sendDtoList.size(); i++) {
            backDto.add(assembSendData(sendDtoList.get(i)));
        }
        return backDto;
    }


    public Object commodityDetailList(HospitalCommodityListVo hospitalCommodityListVo) {
        Page page = PageHelper.startPage(hospitalCommodityListVo.getPage(), hospitalCommodityListVo.getLimit());
        List<GoodsListVo> storeGoodsListByStoreIds = agedmallShopMapper.getStoreGoodsListByStoreIds(hospitalCommodityListVo.getStoreIdList());
        Map<String, Object> map = new HashMap<>();
        map.put("total", page.getTotal());
        map.put("data", storeGoodsListByStoreIds);
        return ResponseUtil.ok(map);
    }

    public Object getMainAndOtherHospitalName(Integer id) {
        AgedmallHospitalSend hospitalSend = agedmallHospitalSendMapper.selectByPrimaryKey(id);
        List<HospitalSendDto> otherHospitalSendList = agedmallShopMapper.getOtherHospitalSendList(id);
        List<AgedmallHospitalSend> backList = new ArrayList<>(otherHospitalSendList);
        backList.add(hospitalSend);
        return ResponseUtil.ok(backList);
    }

    public Object getHospitalStoreGoodsMessage(List<Integer> storeGoodsIdList) {
        List<HospitalGoodsProductDto> hospitalGoodsProductDtos = agedmallShopMapper.selectStoreGoodsProductByStoreGoodsId(storeGoodsIdList);
        for (int i = 0; i < hospitalGoodsProductDtos.size(); i++) {
            List<LitemallGoodsProductSpecification> specifications
                    = JSON.parseArray(hospitalGoodsProductDtos.get(i).getSpec(), LitemallGoodsProductSpecification.class);
            StringBuffer sku = new StringBuffer();
            for (LitemallGoodsProductSpecification lgs : specifications) {
                StringBuffer sb = new StringBuffer();
                sb.append(lgs.getInfoName()).append(":").append(lgs.getName());
                sku.append(sb).append(";");
            }
            hospitalGoodsProductDtos.get(i).setSkuName(sku.toString());
        }
        return ResponseUtil.ok(hospitalGoodsProductDtos);
    }


    public Object addHospitalChannelLink(ModifyHospitalChannelLinkVo modifyHospitalChannelLinkVo) {
        AgedmallHospitalChannelLinkExample channelLinkExample = new AgedmallHospitalChannelLinkExample();
        channelLinkExample.createCriteria().andChannelNameEqualTo(modifyHospitalChannelLinkVo.getName()).
                andHospitalSendIdEqualTo(modifyHospitalChannelLinkVo.getHospitalSendId()).andDeletedEqualTo(false);
        AgedmallHospitalChannelLink channelLink = agedmallHospitalChannelLinkMapper.selectOneByExample(channelLinkExample);
        if (ObjectUtil.isNotNull(channelLink)) {
            return ResponseUtil.fail(500, "渠道名称已存在");
        } else {
            channelLink = new AgedmallHospitalChannelLink();
        }
        channelLink.setHospitalSendId(modifyHospitalChannelLinkVo.getHospitalSendId());
        channelLink.setHospitalIds(modifyHospitalChannelLinkVo.getHospitalIds());
        channelLink.setChannelName(modifyHospitalChannelLinkVo.getName());
        channelLink.setShoppingCart(modifyHospitalChannelLinkVo.getShoppingCart());
        channelLink.setNormalDistribution(modifyHospitalChannelLinkVo.getNormalDistribution());
        channelLink.setOrderRedirection(modifyHospitalChannelLinkVo.getOrderRedirection());
        channelLink.setGoodsShow(modifyHospitalChannelLinkVo.getGoodsShow());
        channelLink.setCarerId(modifyHospitalChannelLinkVo.getCarerId());
        channelLink.setAddTime(LocalDateTime.now());
        String channelLinkUrl = SecureUtil.md5(IdUtil.simpleUUID());
        channelLink.setLinkUrl(channelLinkUrl);
        agedmallHospitalChannelLinkMapper.insertSelective(channelLink);
        return ResponseUtil.ok();
    }

    public Object updateHospitalChannelLink(ModifyHospitalChannelLinkVo modifyHospitalChannelLinkVo) {
        AgedmallHospitalChannelLink hospitalChannelLink = agedmallHospitalChannelLinkMapper.selectByPrimaryKey(modifyHospitalChannelLinkVo.getId());
        AgedmallHospitalChannelLinkExample channelLinkExample = new AgedmallHospitalChannelLinkExample();
        channelLinkExample.createCriteria().andChannelNameEqualTo(modifyHospitalChannelLinkVo.getName()).
                andHospitalSendIdEqualTo(modifyHospitalChannelLinkVo.getHospitalSendId()).andDeletedEqualTo(false);
        AgedmallHospitalChannelLink channelLink = agedmallHospitalChannelLinkMapper.selectOneByExample(channelLinkExample);
        if (ObjectUtil.isNotNull(channelLink) && !hospitalChannelLink.getChannelName().equals(modifyHospitalChannelLinkVo.getName())) {
            return ResponseUtil.fail(500, "渠道名称已存在");
        }
        hospitalChannelLink.setHospitalSendId(modifyHospitalChannelLinkVo.getHospitalSendId());
        hospitalChannelLink.setHospitalIds(modifyHospitalChannelLinkVo.getHospitalIds());
        hospitalChannelLink.setChannelName(modifyHospitalChannelLinkVo.getName());
        hospitalChannelLink.setShoppingCart(modifyHospitalChannelLinkVo.getShoppingCart());
        hospitalChannelLink.setNormalDistribution(modifyHospitalChannelLinkVo.getNormalDistribution());
        hospitalChannelLink.setOrderRedirection(modifyHospitalChannelLinkVo.getOrderRedirection());
        hospitalChannelLink.setGoodsShow(modifyHospitalChannelLinkVo.getGoodsShow());
        hospitalChannelLink.setCarerId(modifyHospitalChannelLinkVo.getCarerId());
        agedmallHospitalChannelLinkMapper.updateByPrimaryKey(hospitalChannelLink);
        return ResponseUtil.ok();
    }

    public Object deleteHospitalChannelLinK(Long id) {
        agedmallHospitalChannelLinkMapper.logicalDeleteByPrimaryKey(id);
        return ResponseUtil.ok();
    }

    public Object hospitalChannelLinkList(HospitalChannelLinkListVo hospitalChannelLinkListVo) {
        Page page = PageHelper.startPage(hospitalChannelLinkListVo.getPage(), hospitalChannelLinkListVo.getLimit());
        List<HospitalChannelLinkBackDto> hospitalChannelLinkBackDtos = agedmallShopMapper.selectHospitalChannelLinkList
                (hospitalChannelLinkListVo.getHospitalSendId(), hospitalChannelLinkListVo.getKeySearch());
        Map<String, Object> map = new HashMap<>();
        map.put("total", page.getTotal());
        map.put("data", hospitalChannelLinkBackDtos);
        return ResponseUtil.ok(map);
    }


    public Object addCollectionPoints(ModifyCollectionPointsVo collectionPointsVo) {
        AgedmallCollectionPointsExample pointsExample = new AgedmallCollectionPointsExample();
        pointsExample.createCriteria().andDeletedEqualTo(false).andNameEqualTo(collectionPointsVo.getName()).andShopIdEqualTo(collectionPointsVo.getShopId());
        AgedmallCollectionPoints collectionPoints = agedmallCollectionPointsMapper.selectOneByExample(pointsExample);
        if (ObjectUtil.isNotNull(collectionPoints)) {
            return ResponseUtil.fail(500, "当前回收点名称已被使用");
        }
        collectionPoints = ModifyCollectionPointsVo.initCollectionPoints(collectionPointsVo);
        collectionPoints.setAddTime(LocalDateTime.now());
        agedmallCollectionPointsMapper.insertSelective(collectionPoints);
        return ResponseUtil.ok();
    }


    public Object modifyCollectionPoints(ModifyCollectionPointsVo collectionPointsVo) {
        AgedmallCollectionPoints collectionPoints = agedmallCollectionPointsMapper.selectByPrimaryKey(collectionPointsVo.getId());
        AgedmallCollectionPointsExample pointsExample = new AgedmallCollectionPointsExample();
        pointsExample.createCriteria().andDeletedEqualTo(false).andNameEqualTo(collectionPointsVo.getName()).andShopIdEqualTo(collectionPointsVo.getShopId());
        AgedmallCollectionPoints checkPointsName = agedmallCollectionPointsMapper.selectOneByExample(pointsExample);
        if (ObjectUtil.isNotNull(checkPointsName) && !collectionPointsVo.getName().equals(collectionPoints.getName())) {
            return ResponseUtil.fail(500, "医院名称已存在");
        }
        collectionPoints = ModifyCollectionPointsVo.initCollectionPoints(collectionPointsVo);
        agedmallCollectionPointsMapper.updateByPrimaryKeySelective(collectionPoints);
        return ResponseUtil.ok();
    }

    public Object deleteCollectionPoints(List<Integer> id) {
        AgedmallCollectionPointsExample collectionPointsExample = new AgedmallCollectionPointsExample();
        collectionPointsExample.createCriteria().andIdIn(id);
        agedmallCollectionPointsMapper.logicalDeleteByExample(collectionPointsExample);
        return ResponseUtil.ok();
    }


    public Object CollectionPointsList(CollectionPointsListVo collectionPointsListVo) {
        Page page = PageHelper.startPage(collectionPointsListVo.getPage(), collectionPointsListVo.getLimit());
        AgedmallCollectionPointsExample collectionPointsExample = new AgedmallCollectionPointsExample();
        collectionPointsExample.createCriteria().andDeletedEqualTo(false).andShopIdEqualTo(collectionPointsListVo.getShopId());
        List<AgedmallCollectionPoints> agedmallCollectionPoints = agedmallCollectionPointsMapper.selectByExample(collectionPointsExample);
        Map<String, Object> map = new HashMap<>();
        map.put("data", agedmallCollectionPoints);
        map.put("total", page.getTotal());
        return ResponseUtil.ok(map);
    }

}
